01-18-2011 07:43 AM - edited 01-18-2011 07:47 AM
EduU,
Out of interest, how big will this array ever get. The reason i ask is that if you are talking about an array that could potentially get large then using 'Build Array' Functions to create your 2 arrays should be avoided. Instead you should try to calculate the size of the 2 arrays, use 'Initialise Array, and then use 'Replace array subset' in your loop:
Just another option to think about, especially if you are going to be using large arrays.
Rgs,
Lucither.
01-18-2011 07:44 AM - edited 01-18-2011 07:44 AM
Here is the 8.2 version
Rgs,
Lucither
01-18-2011 07:56 AM
VI saved in 8.6...
01-18-2011 08:34 AM
Lucither, this array have 7353 numbers on that, you think is too much!?
Thanks for the new example, I will try it and see if I have something different.
01-18-2011 08:49 AM
EduU,
Thats simply answered by benchmarking:
For an array of your size i dont beleive the difference will be significant. The above benchmarks are:
Mine: 2ms
Other: 14ms
The difference would become greater though as the array gets larger.
Another point that was noted when comparing the 2 array outputs. The arrays compiled by the bottom array are in reverse order to how they where initially made. Dont know if this matters to you but if it does you could either reverse the array's or simply change the 'Build Array' input so you are inputting the new value to the bottom (Currently top).
For large arrays (and personally i always do it where possible) it is far more efficient to use 'Replace Array subset', using build array is constantly changing the size of the array which has a lot of overheads and hence takes longer.
Rgs,
Lucither.
01-18-2011 09:01 AM
EduU,
Just to highlight the problems associated with 'Build Array' go to Here. You will see that just by removing 'Build Array' and optimising the original OP's code the speed was improved x1.5Million times! Under tests the original code would execute in 2.5 hours whereas the optimised code ran an average <10ms!
Build Array is evil!
Rgs,
Lucither.
01-18-2011 09:02 AM
Lucither,
Thanks for the explanation!
Well the array isn't my priorioty, but is always good make the things better, one thing i'm having problem to implement your solution is because, this program is develop in LabVIEW 7.1 and in 7.1 we don't have the conditional terminal at for loop, I don't know if this is the problem, but because of that I'm getting only 1 positive number.
Is because of that!?
Thanks
01-18-2011 09:15 AM
Yep, that will be the reason. Here it is without the for loop:
Rgs,
Lucither.
01-18-2011 09:34 AM
Lucither, Thanks for the new VI without conditional terminal!
and I saw the page you linked, oh my god 1.555million times for sure is a lot of time haha
I will put this idea in my program now, thanks
01-18-2011 09:36 AM
EduU,
Just to quickly highlight the problem. If we repeat the above benchmarks but with an array of 1 Million the results are:
Mine: 408ms
Other: 608704ms or 10 minutes and 8 seconds!
I know that 1 Million is a large number but this is just to show how the speed difference becomes a lot larger as the array becomes larger.
Rgs,
Lucither.