I'm trying to find a decent replacement on Windows for
GetTickCount is annoying because it's deliberately biased: when the system resumes from suspend or hibernation, it seems Windows works out how long it was suspended (from motherboard) then adds that to the tick count to make it look like the tick carried on while the system was powered down.
QueryUnbiasedInterruptTime is friendlier: it's a simple, seemingly-reliable counter that just returns the time the system has been running since boot.
Now, I've experimented with
QueryUnbiasedInterruptTime to see what happens when the computer enters each of: sleep, hybrid sleep, and hibernation. It appears that it's correctly updated so that it appears to be monotonic (ie, the system stashes it before hibernation and restores it so that applications aren't confused).
But, there's a note <a href="http://www.python.org/dev/peps/pep-0418/#sleep" rel="nofollow">here on the Python dev pages</a> (which, by the way, are a very helpful resource for time function reference!):<blockquote>
QueryUnbiasedInterruptTime() is not monotonic.</blockquote>
I presume someone did a test to determine that. Is that information accurate? If so, out of interest I wonder what you have to do to get the return value to go backwards.Answer1:
QueryUnbiasedInterruptTime is guaranteed to be monotonic. The interrupt time has no skew added to it, so it always ticks forward although the rate may sometimes differ a little from the wall clock.
I couldn't find any good references for this in MSDN, but I'm now convinced that Hans is right in his comment, the CPython developers must have simply got confused.Answer2:
The main problem with GetTickCount is the value being only 32 bits, i.e. it resets to zero every 50 days of uptime.
You probably need