Solution
To measure elapsed time in a VI that is running, the best way is to use a Flat Sequence Structure in conjunction with a timing VI. Because a Flat Sequence Structure forces code to run sequentially, you can use a timing VI to measure time before and after your code runs. Subtract the time measurement before from the time measurement after to get elapsed time.
The timing VI you should use depends on your use case:
- For simple code measurements, use the Tick Count (ms)function.
- This is a good timing structure if your code runs on the order of milliseconds even up to days.
- The code being measured in the snippet below is a Wait (ms) function. To benchmark your code, replace the Wait (ms) function with your own code.
- The snippet below will run once and give you a single timing comparison. If you would like to run code multiple times to get an average runtime, you can use the Measure Code Execution Time in LabVIEW example code which iterates code and outputs the average execution time.

Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
- If your code needs to run on the order of months, use the Get Date/Time in Seconds unction for timing measurement.
- Again, the code being measured in the snippet below is a Wait (ms) function. To benchmark your code, replace the Wait (ms) function with your own.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
- If you are benchmarking code on a Real-Time target, you can use the Tick Count Express VI and configure it to show the elapsed time in ticks so you will have a more precise result.
- Note that you can use this function on a Windows or other non-deterministic OS, but it will only have precision up to the millisecond.
- Again, the code being measured in the snippet below is a Wait (ms) function. To benchmark your code, replace the Wait (ms) function with your own.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.