LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measure Loop Time

Solved!
Go to solution

I have a program, where communicate with a power supply unit via ethernet. So every loop it sends a command to PSU which is for esample read voltage and PSU replies with the actual voltage. I want to know how much time does it take for the process to finish that is send the command and get the value. How do I measure time from starting of loop and at the end of the loop. Thank you. 

0 Kudos
Message 1 of 6
(963 Views)
Solution
Accepted by govindsankar

This is one of the very rare occasions when you need a Frame sequence, namely for timing things.   You might have noticed that the Timing functions "Tick Count (ms)" and "High Resolution Relative Seconds" have only an output indicator, so you cannot control when they start, except by putting them inside a structure (such as a Frame Sequence).

 

Look inside your code for what you want to time.  Do you have an Error Line that comes in from the left to the first function/structure you want to time, and comes out on the right from the last function/structure, with everything in the middle properly "connected by wires" (and the Error Line is an excellent way to do this)?  Then do the following:

  • Drop a small Frame Sequence on your Block Diagram.  Put one of the two Timing Functions inside it.  Leave enough space above or below the timing function to run the Error Line through, and put this "Start Timer" on the Error Line just before the code you want to time.  Bring the Timer Output out as "Start Time".
  • Drop another small Frame Sequence, with another Timing Function, and place this on the Error Line just after the code you want to time.  Bring the Timer Output out as "End Time".  Subtract Start Time from End Time to get Elapsed Time.

Another way to do this (which is also OK, but, to me, aesthetically less pleasing) is to put a Frame Sequence around the code you want to time.  Right-click the Frame, add another Frame before, and another Frame after, and put the two Timing Function in the first and last Frame.

 

Bob Schor

Message 2 of 6
(951 Views)

THe solution that Bob presented is the best option. I would add to run on a for loop with multiple calls so you can take an average of the time. 

0 Kudos
Message 3 of 6
(929 Views)

Do you want to ...

 

  1. know the elapsed time for each iteration or
  2. the total time from the start of the loop until the loop has completed?

 

Thins might just be a language issues, but your use of the term "every loop", I think you actually mean "every iteration". Please clarify!

 

If you just want the time for each iteration, all you need is place the following inside the loop.

 

altenbach_0-1687788249024.png

 

0 Kudos
Message 4 of 6
(917 Views)

@LVNinja wrote:

THe solution that Bob presented is the best option. I would add to run on a for loop with multiple calls so you can take an average of the time. 


Bob presented TWO solutions...  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 6
(915 Views)

I had an application where I need to be able to time many various parts of the application so I created a basic by reference class that would track execution time for defined sections of code. The class has a create and destroy then two basic methods used in pairs, Start task/Stop task. The task identifier is either a string or ENUM. The class tracks the total execution time, min/max, number of calls and average time for each task. The start and stop methods also have a variant input which only serves as a wire terminal to control execution flow. The class also has accessors for getting the data. It has proven to be very useful as a profiling tool.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 6
(862 Views)