LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to speed up a while loop?

Hi Everybody,

 

I am sure that I have done some noobish things here, but please help me speed up my code. Thing are working marginally at high speeds. I think the code is getting bogged down by the shift registers as the arrays are increased in length. My rotation counter does well for about 50 rotations and then slows down to a stop. I then created a "moving array" that deletes the oldest value and inserts the newest value for Angle, Pressure, and Count. That seemed to help a little, but was not amazing. The code rejects any revolution that does not have 720 data points. Finally, the code compiles data points into a matrix so that all rows of pressure correspond to a similar CAD. I tried "stacking arrays," but made it into a long row. Any ideas would be appreciated. Again, I can get 5-6 cycles to input into the matrix, and maybe 1 or 2 more later, and then it just stops.

0 Kudos
Message 1 of 7
(3,823 Views)

Why are you converting the array to a matrix?  You aren't doing anything with them using matrix functions.  And it is getting converted back to arrays anyway.

 

I don't know if that would be the cause of your problem, but it does seem like unnecessary conversions.

 

Arrays of 1440 elements don't seem to be too big to be causing you many problems.  If you want, you could intialize the array to have that many elements to start with, and manage the indices and lengths of the array to keep track of where the valid data in the array is.  Using Replace Array Subset would replace elements more efficiently rather than building arrays and deleting from arrays.  But I don't know if that would be causing you problems because I don't get the sense you are continuously growing the arrays.

Message 2 of 7
(3,810 Views)

It shouldn't really make a difference, but if you want to remove the first item it's easier to use Split array at index 1 instead of Delete from array and calculating sizes.

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 7
(3,783 Views)

This is a good opportunity to practice benchmarking (depending on how much time you have).

Group some of the functions into subVIs. One at a time, put a subVI in a three-frame flat sequence and feed it simulated data.

0 Kudos
Message 4 of 7
(3,775 Views)

You are constantly growing and shrinking arrays and using way too much code for all this. Allocate all arrays once at the final size, the replace elements, keeping track of the insert points in shift register. I am sure it could be done with 20% of the code. There is so much duplicate code.

 

Replace new data using circular indexing, the reassemble the parts in the correct order once after the loop finishes.

 

 

As another example, here's equivalent code for the second loop (in even includes the transpose operation). Yours is way too convoluted.

 

Message 5 of 7
(3,764 Views)

Thanks for the second loop. Not to worried about the second loop though as it is not time dependant, but It is a nice cleanup. I think you are a labview champion! I am not really good, but I can try to make things do as I please. Any recommendations on how to cleanup the first loop? I truly doubt that it could be done with 20% of the code, but improved upon - yes.

 

Just for the sake of learning... you have index array turned on in your example. Was just curious if that it doing the same thing as my counter on the for loop. I usually turn them off. On that note, can you expain how indexing works with the program?

0 Kudos
Message 6 of 7
(3,732 Views)

@bronco9588 wrote:

 

Just for the sake of learning... you have index array turned on in your example. Was just curious if that it doing the same thing as my counter on the for loop. I usually turn them off.



Yes, auto indexing will do the same thing. You have to be careful though, if you autoindex multiple arrays that are not the same size, your for loop will exit after looping through all the elements in the smaller array. So make sure your arrays will always be the same size before using autoindexing on multiple. To put a text based spin on things, basically autoindexing is like doing "for each x in y" in VB. Also, why do you have a +0 on your counter in the for loop Smiley Tongue

0 Kudos
Message 7 of 7
(3,726 Views)