ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Milliseconds Delay and Measuring execution time of code

I am currently using a dummy loop as a delay in my code. I know this will not work in every computer because of processor speed differences and workload. I'd like to replace this code with a delay, but I haven't found one that delays for X milliseconds, only seconds. I need two things:

1. How do I find out how long my loop is taking to execute? (So I'll know how long my delay is in ms)

for (delayLoop = 0; delayLoop < 80000; delayLoop++)
{
dummy++;
}

2. How do I put in a delay in milliseconds? It seems like Delay, Timer, and SyncWait are all for "seconds" delays.

Thank you.
0 Kudos
Message 1 of 3
(4,229 Views)
Hi,

1. To know the time of the loop, start the Timer() before the loop and call it again after the loop and take the difference.

2. Delay function takes double value as an argument , so you can specify a millisecond value also.

Regards,
Siddu
0 Kudos
Message 2 of 3
(4,223 Views)
To delay 1 millisecond: Delay(.001)

To measure your loop time try this.

double t_start, t_stop, delta;

t_start = Timer();

your loop...

t_stop = Timer();

delta = t_stop-t_start;

'Hope this helps!

w
0 Kudos
Message 3 of 3
(4,099 Views)