Reputation: 170
I found an example of QueryPerformanceCounter,
http://advancedcppwithexamples.blogspot.com/2009/08/measuring-elapsed-time-in-c-using_21.html
The example measures a sleep of 100ms with QueryPerformanceCounter which reports only 79ms.
Is there a reason sleep is so inaccurate?
Upvotes: 0
Views: 1512
Reputation: 308138
sleep
is inaccurate for two reasons: it's based on a very slow clock, and it relies on the OS to resume execution at the end of the period.
The performance counter is actually built into the CPU so it's as accurate as the clock signal that runs the chip. It isn't affected by the OS or tasks whatsoever.
Upvotes: 3