Microsecond timer available on Windows?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I'm doing some speed optimization on my Visual C++ program. I'm using
timers throughout the program. I'm calling ftime() which works well, but
only returns current time to a millisecond accuracy. I've gotten to the
point where I now need even more precision in my timers.

Many unix platforms have a function gettimeofday() which has microsecond
accuracy, but this function is not available on Windows, apparently.

Question: Is there a way on Windows (Visual C++) to get current time with
microsecond (or better) accuracy?
 
noleander said:
Hi. I'm doing some speed optimization on my Visual C++ program.
I'm using timers throughout the program. I'm calling ftime() which
works well, but only returns current time to a millisecond accuracy.
I've gotten to the point where I now need even more precision in my
timers.

Many unix platforms have a function gettimeofday() which has
microsecond accuracy, but this function is not available on Windows,
apparently.

Actually, it has microsecond resolution. It's unlikely that it has
microsecond accuracy or precision on the vast majority of *nix platforms.
Question: Is there a way on Windows (Visual C++) to get current time
with microsecond (or better) accuracy?

Use QueryPerformanceCounter/QueryPerformanceFrequency to measure short
intervals at high resolution. On most modern PCs, QPC measures in CPU
clock cycles.

-cd
 
Back
Top