07-25-2012 01:57 PM
Hello fellow LabVIEW users
I have encountered huge problem that following for loop takes way too long to execute, I need to run two same for loops like the following one and they both together take horribly long time - 18 seconds on average. Surprisingly, when I combined both loops it took even longer.
For loop above is doing (or should do) following part of code:
for i = 1 : 11850 signalAvr(i) = signal(i); for j = 1 : 149 signalAvr(i) = signalAvr(i) + signal(i + j); end end
Is there any way of speeding up this loop? What am I doing wrong?
Thanks
Smdx
Solved! Go to Solution.
07-25-2012 02:31 PM
The build array is taking a lot of time because it is constantly grabbing more memory. Instead, use the autoindex tunnel to build your array. LabVIEW will preallocate the memory for the array and will run a lot faster.
07-25-2012 02:32 PM
One thing that is absolutely killing you is the fact that you're reading a local variable 1765650 times each time you run this vi.
07-25-2012 02:33 PM
I think you are doing it way to complicated.
Try this:
NOTE: My local variable is somehow **bleep**ed. The reference control together with the property node should be a local variable.
07-25-2012 02:38 PM - edited 07-25-2012 02:41 PM
I haven't fully tested it, but see if this will work for you. It is a lot simpler.
EDIT: Ok, dkfire beat me to it. At least we came up with the same solution independently. I just use the autoindex tunnel where he preallocated the array and replaced elements. Both ways will get you the same result.
07-25-2012 02:48 PM
@dkfire wrote:
NOTE: My local variable is somehow **bleep**ed. The reference control together with the property node should be a local variable.
Use the Code Capture Tool, it is so much better than the built-in LabVIEW snippet menu choice. It doesn't break locals and references.
07-25-2012 02:49 PM - edited 07-25-2012 02:58 PM
Looks like you guys beat me to it, but I will post my solution anyways.
***EDIT: I need a shift register in the inner loop and should be autoindexing on the outer loop****
07-25-2012 02:52 PM
@lacVIEW wrote:
Looks like you guys beat me to it, but I will post my solution anyways.
That solution will not work. For that method, you need a shift register in the inner loop and you should be autoindexing on the outer loop.