08-23-2013 03:28 AM - edited 08-23-2013 03:37 AM
from Labview Idea Exchange : @altenbach le 08-23-2013 07:01 AM
Please start a regular thread and post your benchmark code.
My guess is that the second code is artificially fast due to constant folding and thus not a valid reference point.
This needs to be discussed in detail elsewhere.
Hello everyone,
Just a small question because I am amazed ...
Why is the Mean_function so slow?
8ms vs 1304ms ???
Thanks to all
08-23-2013 04:35 AM - edited 08-23-2013 04:40 AM
08-23-2013 05:16 AM
If you don't understand what the constant folding means check out the page at http://zone.ni.com/devzone/cda/pub/p/id/347 - so in effect with your benchmark, the dll is being called 10000 times while the code in the loop is only being called once - I think the rates look pretty good to me, in fact, in order to remove the constant folding I called the CONTENTS of the both loops as subVIs - and the difference was then about 60ms on my machine between the two. Without the subVIs I was getting about 120ms on the dll vi (so a sub VI anyway) and 0 on the constant folded maths, put the maths into a subVI (so that it is a fiarer test really as then both are calling another VI) and it jumped up to about 170ms (no more constant folding, going off to somewhere else - a bit like the other one...)
Why is the Mean function so slow - it isn't, in fact in a like for like test (subVI call within a for loop of either the dll using the mean function or a sum array divided by array size - I just highlighted the code and created a subVI) then doing the code by hand is slightly slower on a very simple benchmark test such as the one in the original post
08-23-2013 06:01 AM - edited 08-23-2013 06:19 AM
ok
i didn't know the "constant folding" !
i have disabled the "constant folding" with a shift register, like this :
How to disable "constant folding"? Is it possible to do this? (Maybe in the .ini file?)
08-23-2013 06:44 AM
Now if you move the DLL call from within the "Mean.vi" out into the For Loop for testing you'll also lose the sub-VI call overhead fromy our benchmark.
08-23-2013 07:01 AM
little or no sub-VI call overhead,
I don't see change, the results are the same. (131/51)
But on the heart of the problem, you are right.
08-23-2013 07:17 AM
Here's my benchmarking (done in 2012). I am getting a 3x improvement by using the primitives. I still have some ideas of a few things to try though.
I think the DLL is doing extra checks in there to make sure we don't have an overflow. That would cause the slow down.
08-23-2013 07:28 AM - edited 08-23-2013 07:29 AM
I was right. The DLL code is using an algorithm that avoids overflow to INF. Here is my final benchmark. Now, how often would you run into this situation? I would think it is very rare. But that is the reason for the time difference.
08-23-2013 07:33 AM
Well at least we finally got to a value which we can discuss.
The pitfalls of Benchmarking code are many.
Shane.
08-23-2013 07:49 AM - edited 08-23-2013 07:51 AM
Ok, one final benchmark in attempt to put this DLL call slow business to sleep. Here is how I figured NI is doing the average: Sum(X/size(X)). This is pure speculation, so if somebody can direct me to a better algorithm that avoids the overflow, let me know.