You have a requirement to build an array of random U8 numerical values using a loop. Put the following methods and loop types in order of performance (quickest to slowest)?
a) For loop using "auto indexing"b) For loop using "build array" and a Shift Registerc) While loop using "auto indexing"d) While loop using "build array" and a Shift Register
A C B D
A, C, B, D
can it be C A D B ??????
No, A is definitely the most efficient. The reason is because a FOR loop has a fixed number of iterations. So the Autoindex tunnel has a preallocated array.
The While Loop with the autoindex is next because of how the compiler incrementally preallocates more memory for the output tunnel. Put simply, it doubles the memory when the allocated memory is used up.
B and D I would say are about the same since the Build Array forces a memory reallocation each time it is ran.
So I had a go and got the following timings for making an array of 100,000 U8 numbers (in seconds)
c) 0.015 (which is pretty quick, I thought this would have taken longer)
I guess the difference between b&d is code I added to decide when to stop the while loop?
I just did a benchmark of generating 1M random doubles for each method and averaged over 100 iterations. I got the following average times:
FOR Autoindexing: 22.52ms
While Autoindexing: 25.17ms
FOR Shift Register: 122.82ms
While Shift Register: 280.99ms
NOTE: LabVIEW 2016 32-bit, made sure debugging was turned off
I can’t offer a detailed explanation. But my assumption was the same: A For loop should be faster than a while loop (more work to do with comparisons, open end till condition) and auto index should be faster than build function (build function seems to me a more universal and complex function). Second reason seems more significant than first reason. So A-C-B-D
my gut feeling says A, C, B+D
i know that A must be the fastest, because the array will be allacoted in the proper size since it is known how big it must be,
B second because i guess there will be some fancy optimization to allocate array ressources efficiently.
B+D should be somewhat equal, since in each step the new array has to be allocated.
EDIT: oh nice .. mostly right, although i am now curious how crossrulez' B and D differ by a factor of 2, i would have guessed timsrize's result to be the one. any explanations for the difference?
Following the techniques taught in Core l and Core ll, I would say the correct answer is:
A, C, B, D;
See you soon.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.