04-27-2017 06:29 AM - edited 04-27-2017 06:32 AM
putting the "absolute" and "increment" functions inside the the inner loop would be better if we want to haggle constants in quadratic algorithms 😉
:cheers:
04-27-2017 09:55 AM - edited 04-28-2017 10:56 AM
@jwscs wrote:
putting the "absolute" and "increment" functions inside the the inner loop would be better if we want to haggle constants in quadratic algorithms 😉
Yes, there is no way to tell without measuring, however your benchmark is flawed. Once you disable debugging, both times go to zero because of "dead code elimination" and "constant folding". The debugging overhead is different for the two code fragments, so all bets are off. But yes, once we replace the constant with a control and add an output (e.g. the array sum of the two 2D arrays so we don't run out of memory on 32bit LabVIEW because of the gigantic indicator data), the difference is even smaller. Still, the newer code suggestions are even (>25%) faster. For very large N, the fastest seems to be a hybrid with the abs/increment in the second loop. We can go even faster by parallelizing the second loop, but I have not tried on a high core count machine. For smaller inputs, the parallelization is probably not worth it.
Still the differences are within a factor of two and thus irrelevant. It might even be different on a different OS, LabVIEW version, or CPU type (architecture, cache size, etc.). A comprehensive benchmark would be difficult to do.
04-28-2017 03:17 AM
i agree to your points.
my cs schooling just made me see the multiple array accesses from the abs/increment as a lighthouse 😉
unfortunately i do not know enough anything about how the labview compiler handles such things, no time to learn yet.
:cheers: and thx for the kudos
04-28-2017 10:55 AM
@jwscs wrote:
:cheers: and thx for the kudos
Oh, I always love when benchmarking is brought up. It is a very difficult, but interesting topic. So thanks!
See also my presentations. 😄