LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do i create arrays more efficiently

I did a small test program. 10 million random numbers build an array (*2), one through indexing, 1 through preallocation with Initialize array and then replace. Loop and rebuild 100 times and check the result. This is my result!
It might be affected by version and system, but automatic indexing is FASTER than Replacing a preallocated array. 🙂

 

Array creation.png

 



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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 11 of 27
(2,551 Views)
You may be comparing apples to oranges. If you need to initialize an array with a single value, then the initialize array function and the for loop with a constant should take about the same amount of time.
0 Kudos
Message 12 of 27
(2,540 Views)

Yamaeda wrote:
I did a small test program.

 

 
Without seeing the code, I don't trust any benchmarks.
(Even with full access to the code, I take such benchmarks with a grain of salt).
 
At least show us the diagram or attach the program. 😉 
0 Kudos
Message 13 of 27
(2,529 Views)

@altenbach wrote:
 
Without seeing the code, I don't trust any benchmarks.
(Even with full access to the code, I take such benchmarks with a grain of salt).
 
At least show us the diagram or attach the program. 😉  

 

Mah, i knew you'd say that. Ofc i forgot to save it, but this recreation is pretty identical (except the slider).

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 14 of 27
(2,516 Views)

Yes, the difference is quite significant but probably not worth it. 80-90% of the loop timing is taken up by the random number generator, so if we subtract the time to generate the random numbers, the true difference is even bigger.

 

OTOH, we can see that any real computation will be significantly more dominant, making the empty loop differences insignificant in comparison. We would try to improve something that is only a very small percentage of any typical loop computation.

 

Interestingly, the autoidenxing loop has a bigger debugging overhead. Once we disable debugging, the differences are even bigger.

 

Results with an inner loop N=1000000:

 

autoindex: (69ms, 64ms*)

replace: (74ms, 72ms*)                  *second number is with debugging disabled

 

 

0 Kudos
Message 15 of 27
(2,509 Views)
The main point is that the easiest coding is in this case also the fastest! \o/
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 16 of 27
(2,472 Views)

Prior to LV 6i the preallocate and replace was faster.

 

As of LV 6i, a lot enhancements where implmented such that the For loop will preallocate the buffer when it starts and is slight faster than coding it up the hard way.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 17 of 27
(2,444 Views)
Wow! thanks for all the responses.  I was reluctant to post my code because of my inexperience with labview.  I have attached my code in a picture.  Essentially what I am trying to do is read data from a stream. The stream reading function (the thing with sunglasses) can apparently be set up to stream at 10 Hz, or just pull the last value from memory.  I wanted to be able to use the code in either stream configuration. I just wanted to record value, and time in x,y pairs and write it to a file at a rate set by the ms to wait tick clock.  However I was trying to use all the data to calculate statistics.  This is where i thought i was running into trouble...@ 10 Hz, I had 288,000 values stored in an array, using shift registers (at 8 hours) when it crashed.  From what i have read, this doesn't seem like the culprit. I realize the write to file, and the stats calcs also use memory... but i don't really have a concept of how much or which is worse. I have the write to file appending to inself in the inner loop as to not lose data.  The outer loop one just writes over itself...keeping only the last value. There are some fixes I notice i can make right away.. maybe try linking the index to only the N (last value) and pulling the array constants out of the loop? I have trouble passing data through tunnels sometimes.  I don't really know how big they will be.. unless i specify it and stop the loop then, but i like to have a run continious option.  I could also re-write the stats functions in a more memory friendly way...but i didn't want to unless i had to.  Also it should be noted that i have the base version of labview...version 2.9.... be gentle.
0 Kudos
Message 18 of 27
(2,434 Views)

There is no LabVIEW version 2.9. 2009 perhaps?

 

What you are doing will not work. You are inserting elements into empty arrays. This only works if the index is zero and not for random indices. All you probably need to do is use "built array" with two inputs (value and time) and append the resulting 1D array to your spreadsheet.

 

Please attach your actual VI so we can give you some useful tips on how to do it better. 

0 Kudos
Message 19 of 27
(2,427 Views)
yes.. version 2009. sorry.  ok here is the file... it won't run without the instrument but maybe its an easy swap to create a different stream?  It does work and does what i want it to do... until it crashes 🙂  thanks for all the help!
0 Kudos
Message 20 of 27
(2,409 Views)