08-03-2012 04:09 AM
Hi All,
I am trying to avoid making multiple copies to Improve efficiency. Attached is the vi taken from a larger program. The idea here is to replace 2 D array(Image data) at each iteration, the vi attached shows the first 8 pages of the 3d array is being replaced. This number could change ,that is why I’m allocating 100 pages on the 3d constant. However, the performance of the vi seems to be dependent on the 3d array size which might suggest to me that I’m making data copies for each iteration. In theory, if what we are doing inside the for loop is just replacing the 2D array of 0 to 7 pages, the performance should be independent of the 3d array size? I have used the “show buffer allocation “ tool and there is not buffer allocated at the shift register. Does this mean that we are not making multiple copies for each iteration?
Please advice
Thanks
08-03-2012 05:01 AM
The shift register does not make copies at the terminals.
Playing with your example code a bit, if I take your 3D array constant and replace it with an Init Array function then I can easily change the number of pages. However, the number of pages has no effect on the execution time. 10 pages to 310 pages all take approximately 700ms to execute your for loop, so I cannot reproduce the issue you are describing.
08-03-2012 05:39 AM - edited 08-03-2012 05:40 AM
Another way for speeding up if you working with images you can use IMAQ Vision functions instead of arrays.
The following code which is functionally equivalent with yours will take less than 100 ms in comparison with your version which takes 670 ms on my PC:
08-03-2012 05:40 AM
A 3D array very quickly grows in size, you're not running out of memory and get swapping? That'd explain rapid speed degeneration over certain sizes.
/Y
08-03-2012 05:45 AM
08-03-2012 09:47 AM
Well, you array has 31M element, using 120+ MB of memory. This will not fit in the processor cache, so there is some penalty.
You have to be really careful with constant folding, because you are using diagram constants. If I disable debugging in your code, it executes in 0 ms because everything is folded. After replacing the constants with controls to avoid folding, it still executes 20x faster than with debugging enabled. A lot of the overhead seems to be in the debugging code.
(I would also wire the output to somewhere, else the compiler might eliminate the entire thing as part of dead code elimination.)