LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Execution time for while-loops?

Hi,

How can I measure the time used during one iteration in a while-loop?

Dennis
0 Kudos
Message 1 of 3
(2,901 Views)
Prior to the loop get the time. Initialize a shift register in the loop with that time. Now - at the end of the code in the while loop get the time once again, and find the difference between the value in the shift register and the new time. Wire the new time to the right hand shift register terminal...when you loop the difference will now tell how long each iteration takes.

In the attached example I have usied the get ms timer value to get the current time. The ms timer loops though so there is a possibility that it will give an incorrect value just when it resets...normally that's not a big problem, unless you want to do something critical based on the loop time...

In the example the loop code is just an add operation and a wait until next multiple (to
make the loop use some time), you can remove all that and put in your own code, or better - just add the timer code to your own loop.

PS. The example illustrates one thing about the wait next ms function that people sometimes overlook; the first time it is run it does not have a start value to relate to so it won't wait the specified number of ms on the first iteration.
Message 2 of 3
(2,901 Views)
If your loop is really fast (a few ms or less) add some logic to only run the new time and difference operation every N iterations, then you get the loop time for N iterations. You can then get a good average time by dividing that by N.
0 Kudos
Message 3 of 3
(2,901 Views)