Does anybody knows of a function or a link where I can find a function that will give me the time in milliseconds for an interval of time...???
I would really appreciate it,
Thanks.
Printable View
Does anybody knows of a function or a link where I can find a function that will give me the time in milliseconds for an interval of time...???
I would really appreciate it,
Thanks.
You can use gettimeofday(). Call it once before, and once after the event you're trying to time. Then just take the difference of the times and blamo, you've got it.
you can use this one
delay(1000);
here the computer waits for 1000 nano seconds as mentioned in brackets
what sort of program do u want to do??
is that a sort of stop watch??
the function "clock" will give you some sort of "fraction of a second" time, it may not be milliseconds, but it's the most portable "short time" function. Include "time.h" and use "CLOCKS_PER_SEC" to figure out what the time is (use float/double to mace it fractions of a second). Also use "clock_t" as the type for the result of the function.
If that's not precise enough, QueryPerformanceCounter/QueryPerformanceCounterFrequency is a Windows function set that will give you around 1 us or better resolution.
gettimeofday() on Linux will be pretty good too.
Or "rdtsc", which is an assembler instruction to read the number of clock-cycles as a 64-bit number in EAX/EDX (assuming x86 processor of course).
I'd try "clock()" first, then work down the list as/if needed.
--
Mats