How accurate are the various Windows time-querying functions?

Raymond Chen

Windows has a bunch of time-querying functions. One group of functions uses the system performance counter. These are as accurate as the hardware allows while still conforming to the basic requirements (such as running at a constant speed and being consistent among multiple processors).

  • Query­Performance­Counter gives you the current performance counter, and
  • Query­Performance­Frequency tells you the frequency of the performance counter.

Another group uses the system timer, which usually means 55ms or 10ms, although the time­Begin­Period function can be used to run the timer at a higher rate.

  • Get­Tick­Count, Get­Tick­Count64
  • Get­Message­Time
  • Get­System­Time, Get­Local­Time, Get­System­Time­As­File­Time
  • Query­Interrupt­Time, Query­Unbiased­Interrupt­Time

And then there are the so-called precise¹ variants of the system timer functions. These take the system timer value and combine it with the system performance counter to get a high-accuracy timestamp. It’s not only querying two timers, but it’s also doing additional computations to combine the values, so naturally this is slower than querying just one of the two timers, but hey, a fine wine takes time.

  • Get­System­Time­Precise­As­File­Time
  • Query­Interrupt­Time­Precise, Query­Unbiased­Interrupt­Time­Precise

These high-accuracy functions give you the best of both worlds: Time correlated with real-world clocks, but with the accuracy of the system performance counter. But as noted, it comes at a performance cost.

¹ Though to be pedantic, they should be called the accurate variants.

0 comments

Discussion is closed.

Feedback usabilla icon