06-26-2023 08:03 AM
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.
Solved! Go to Solution.
06-26-2023 08:23 AM
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:
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
06-26-2023 08:49 AM
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.
06-26-2023 09:04 AM
Do you want to ...
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.
06-26-2023 09:05 AM
@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... 😄
06-26-2023 01:01 PM
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.