LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mean Fonction (?)

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?

 

SR1.png

 

 

SR2.png

 

8ms vs 1304ms ???

 

Thanks to all

 

0 Kudos
Message 1 of 22
(4,661 Views)

Hi ouadji,

 

Altenbach already gave you the answer, so what else do you expect here when reposting that question?

 

See this BD with activated "constant folding" display:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 22
(4,634 Views)

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

Message 3 of 22
(4,617 Views)

ok

i didn't know the "constant folding" !

i have disabled the "constant folding" with a shift register, like this :

 

SR4.png

 

 

How to disable "constant folding"? Is it possible to do this? (Maybe in the .ini file?)

 

 

 

 

0 Kudos
Message 4 of 22
(4,601 Views)

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.

Message 5 of 22
(4,578 Views)

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.

0 Kudos
Message 6 of 22
(4,563 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 22
(4,553 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 22
(4,544 Views)

Well at least we finally got to a value which we can discuss.

 

The pitfalls of Benchmarking code are many.

 

Shane.

0 Kudos
Message 9 of 22
(4,537 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 10 of 22
(4,524 Views)