0

I have written a C++ program to print the timestamps(or system time) at the start of two events. But the difference between these two times is always a 0 or 15ms. This is because the Windows XP timer updates itself 64 times per second i.e once every 15.625ms. So i don't have a way to know any delay between 0 and 15.625ms.

Is there a way to work around this restriction?

Thanks in advance.

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
Vigo
  • 707
  • 4
  • 11
  • 29
  • How do you currently get the timestamp? – Peopleware Feb 27 '13 at 10:13
  • 1
    possible duplicate of [Reliable high-resolution timer on Windows XP](http://stackoverflow.com/questions/2274873/win32-api-timers/2274896#2274896) and [How can I get the Windows system time with millisecond resolution?](http://stackoverflow.com/questions/3729169/how-can-i-get-the-windows-system-time-with-millisecond-resolution) – Raymond Chen Feb 27 '13 at 13:01

1 Answers1

3

Check out QueryPerformanceCounter to get a higher resolution.

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
  • 1
    + `QueryPerformanceFrequency()`. – Alexey Frunze Feb 27 '13 at 10:14
  • All these time I was using boost::posix_time::microsec_clock::local_time(). QueryPerformanceCounter + QueryPerformanceFrequency() served the purpose of my code! Thanks a ton! – Vigo Feb 27 '13 at 11:29
  • Note that `QueryPerformanceCounter` is not stable over long periods of time. Other past similar questions (duplicates) cover this aspect. – Roman R. Feb 27 '13 at 13:28