LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop too SLOW: can you suggest me anything to improve the speed?

Solved!
Go to solution

I have a vi which is TREMENDOUSLY SLOW. The part which slows everithing is the piece I put in the attachment. 

What I am doing is the following: I select the elements from a variable X (which can be a 1D or a 2D array), when a condition on another variable Y is put (lower and upper limits). 

I think it is a problem of memory. The arrays are more or less 200000 elements. The first 30000 thousands are processed reasonably fast, but then it becomes slower and slower and slower (after 30 minutes is still running, and it is a problem, since I should use this vi several times, changing upper lower and lower limits, set of data to be processed, etc....).

I would ask you, if you have any idea on how to solve such an issue, if you can suggest me something to improve the speed. 

I am using LV 2012 on a machine with Vista.

Thank you

0 Kudos
Message 1 of 12
(4,007 Views)

The conditional tunnel has performance problems when the arrays get big. You should operate on the arrays in place and trim at the end.

 

Can you attach the actuall VI example instead of a picture?

Message 2 of 12
(3,994 Views)

Why invent the wheel? Wire the arrays to In range and coerce.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
Message 3 of 12
(3,992 Views)

@Yamaeda wrote:

Why invent the wheel? Wire the arrays to In range and coerce.


It seems he wants to trim seveal other arrays according to the range condition of only one of the arrays.

Message 4 of 12
(3,989 Views)
Solution
Accepted by topic author gnappo

Ah, right. I misread it like he wanted the same limits for all arrays, and coercing 3 arrays of 100k elements took me 6ms.

Here's an alternative that takes me 5ms.

InRangeAndCoerce.png

 

/Yamaeda

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

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 12
(3,981 Views)

Here's what I had in mind. Modify as needed. See if it is any faster. 😄

 

 

 

Download All
Message 6 of 12
(3,971 Views)

Hi thank to all of you. Sorry Altenbach I could not include the all vi, but it was huge with several subvis, further it had a tdms file to read the vectors-> then...how could I satisfy your request?

Anyway, GOOD NEWS, I solved my problem. The solution was triggered by the Yamaeda post. Because in my pc, which is slower than his one, I made his vi running and I got 20ms. 

Now I asked myself: what is the difference between yameda vi and mine. Well, the difference was the 2D array. I modified my program to split the 2d into 1d arrays, I made the trick and then rejoined the 1d arrays into a 2d array. 

It seems rather incredible, but now it takes a couple of seconds to run. 

I am also going to try the altenbach suggestion, since I am a fan of him and he always give good suggestions. 

Thank you

0 Kudos
Message 7 of 12
(3,947 Views)

@gnappo wrote:

Well, the difference was the 2D array. I modified my program to split the 2d into 1d arrays, I made the trick and then rejoined the 1d arrays into a 2d array. 


It was not clear that that was a viable solution. Somethmes 2D arrays are big in both dimensions. 😄


@gnappo wrote:

I am also going to try the altenbach suggestion, since I am a fan of him and he always give good suggestions. 


Mine has the advantage that it does not need any memory allocations during the run of the FOR loop (and that it easily handles 2D arrays ;)) It probably will perform significantly better for large arrays.

0 Kudos
Message 8 of 12
(3,936 Views)

Impressive, i didn't think it'd differ that much, ~20ms to 4,5. By separating your loop to 3 i shaved off yet some to ~3,5ms.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 12
(3,932 Views)

@gnappo wrote:

Hi thank to all of you. Sorry Altenbach I could not include the all vi, but it was huge with several subvis, further it had a tdms file to read the vectors-> then...how could I satisfy your request?

Anyway, GOOD NEWS, I solved my problem. The solution was triggered by the Yamaeda post. Because in my pc, which is slower than his one, I made his vi running and I got 20ms. 

Now I asked myself: what is the difference between yameda vi and mine. Well, the difference was the 2D array. I modified my program to split the 2d into 1d arrays, I made the trick and then rejoined the 1d arrays into a 2d array. 

It seems rather incredible, but now it takes a couple of seconds to run. 

I am also going to try the altenbach suggestion, since I am a fan of him and he always give good suggestions. 

Thank you


Actually they seem similar, when i in the bottom generator loop added a Build array so i got a 2D array of 100k x 1 it took me 20ms also.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 12
(3,927 Views)