LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create a time trial program to compare the average execution times of the formula node and the native labview functions

I am new to Labview and am trying to work through some of the problems in my book.  The following has me completely confused.  I don't even know where to start. Please help

 

Create a time trial program to compare the average execution times of the “Formula Node” and the native LabVIEW Math Function. This program will require a For Loop, a Flat Sequence Structure, and a Case Structure. The For Loop is required to run the time trial N times and then the results can be averaged using the “Statistics” function in the Probability $ Statistics sub-palette. The Sequence Structure is required to sample the “Tick Count” before and after the code executes. The Case Structure is required to determine whether the user would like to execute the Formula Node or the native LabVIEW Math Functions. To test the timing, using the following formulas:

a = X 2 / 4;

b=(2× X)+ 1;

Y=sin(a b);

0 Kudos
Message 1 of 14
(4,675 Views)

Homework, obviously. Well, with any homework problem, where do you start? You start with what's being asked. What's being asked? To time the execution time of a VI. How do you do that? Well, there are several ways. The suggested method in the homework question is to use a sequence structure. Why? Well, how do you calculate execution time? You get a time stamp at the start, do the action, and get a time stamp at the end. Subtract. So, create a VI that does that. The middle frame is where you place the code that you're supposed to run. What's the code that you're supposed to run? A calculation. What calculation? Well, you're supposed to calculate "a" and "b" and then "Y". "X" is an input. So what do you need? An input control for "X" and an output indicator for "Y".

 

Do that, and get back to us.

 

We will not do your homework for you.

0 Kudos
Message 2 of 14
(4,664 Views)

How old is that book? Who wrote it?

 

Even if you would perfectly follow the instructions, the result would most likely be meaningless. If you run the simple code N times in a for loop and meaure the execution speed with every iteration, you get a huge array of N elapsed times that are most likely all zero and taking the average later will not change that. Most likely, the slowest component is measuring the ticks. Instead, you need to measure the overall time of running the loop N times and divide the result by N to get the average. No statistics palette needed. Of course you could repeat that several times with a seocnd outer loop and do the statistics there. 😉

If you do that and try to simply calculate the same thing N times, the LabVIEW compiler will be smart enough and calculate the code only once and fold it into a constant, making it look much faster than it really is, and again you won't see a real speed difference.

 

Reliable benchmarking is very hard and many things need to be considered. It can be done right with a few little modifications.

 

In any case where exactly do you have problems with the description?

 

  1. Create a three-frame flat sequence and place a tick count in the first and last frame. After the last frame subtract the two tick values (last-first) to get the elapsed time for the frame in the middle in milliseconds.
  2. In the middle frame, add your FOR loop and implement one of your formulas. See if you can measure the speed and see if the result makes sense. Does it take 10x longer if you increase N by a factor of 10?
  3. One this is working, place a case structure around the inner code and implement the other formulas. Add a case selector (e.g. an enum) to pick which case to execute.

See how far you get and post when you think you are ready so we can give advice on how to improve it. 😄

 

0 Kudos
Message 3 of 14
(4,663 Views)

I can not get my formula node to run with the folowing equations.  Not sure how to set up the syntax.

a = X 2 / 4;

b=(2× X)+ 1;

Y=sin(a b);

I put them in as follows;

 a=(x**2)/4;

b+(2*x)+1)

y=sin(a+b);

 

I keep getting an error:  Formula Node: Undefined Variable

 

With x set as my input and y as my out put.

Anyy advise?

0 Kudos
Message 4 of 14
(4,649 Views)

Why is there a "+" after the "b"?

Why is there no semicolon in the second line?

Did you create all the needed inputs and outputs?

When you press the broken run arrow, the error details should point to the problem section

Show us your code!

0 Kudos
Message 5 of 14
(4,647 Views)

I will try and post what i have.  I am working through a virtual upc at my school.  and the connection is very slow.

0 Kudos
Message 6 of 14
(4,639 Views)

As altenbach pointed out you need a for loop to get meaningful times.  On my computer the average time to run the corrected formula node is about 90 ns.

 

When you have a broken run arrow, clicking on the arrow will tell you the cause of the error.  In your case you have undefined outputs.  Even though you are not using the values outside the Formula Node, a and b are still considered "outputs" because you assign values to them.

 

The native functions are about 3 times faster for this calculation.

 

Lynn

0 Kudos
Message 8 of 14
(4,621 Views)

So i feel like im close!  However i need help with my average, and my tick counter.  Also do i need to add a delay.

 

0 Kudos
Message 9 of 14
(4,607 Views)

I am not sure what kind of help you need.  Can you be more specific?

 

You do not need or want a delay in this kind of program.  When people talk about putting delays in loops, it is for two reasons. 1. To set the minimum time for each iteration. 2. To allow CPU sharing so that parallel code can execute without waiting for the loop to finish.  When you are doing timing tests, neither of these reasons applies.

 

As altenbach pointed out, good benchmarking is not always easy.  For example the value of X makes a difference.  For X = 0 times are much shorter.  I suspect that some of the math functions are clever enough to know that zero produces a special result which does not need to be calculated.  Also your calcuations are fast enough that the time required for the case structure is significant.  Your code runs in about 97 nanoseconds on my system with X = 0. On my program which has separate sequence structures for each implementation of the calculations the times are 30-70 nanoseconds.

 

In the plots I see some behavior which I cannot explain.  Occasionally the times jump up by 20-30% and it often does it on all three implementations at the same values of X*i.  Since the for loops execute at different times it is not likely that this phenomenon is due to OS latencies.  Each run of 100 calls to the sequence structures usually exhibits this, but not consistently at the same values of X*i from run to run.

 

Lynn

0 Kudos
Message 10 of 14
(4,592 Views)