Rollover/wraparound time of time.clock() under win32?

Russell Warren russandheather at gmail.com
Wed Sep 28 18:50:30 EDT 2005


Does anyone know how long it takes for time.clock() to roll over under
win32?

I'm aware that it uses QueryPerformanceCounter under win32... when I've
used this in the past (other languages) it is a great high-res 64-bit
performance counter that doesn't roll-over for many (many) years, but
I'm worried about how many bits Python uses for it and when it will
roll over.  I need it to take years to roll over.  I'm also aware that
the actual rollover 'time' will be dependent on
QueryPerformanceFrequency, so I guess my real question is how Python
internally tracks the counter (eg: a 32 bit float would be no good),
but the first question is easier to ask. :)

time.time() is not an option for me since I need ms'ish precision and
under win32 it is at best using the 18.2Hz interrupt, and at worst it
is way worse.

I'd like to avoid having to make direct win32api calls if at all
possible.

In general - if anyone has any other approaches (preferrably platform
independent) for getting a < 1 ms resolution timer that doesn't roll
over for years, I'd like to hear it!

For now I have (for win32 and linux only):
#---
from sys import platform
if platform == 'win32':
  from time import clock as TimeStamp
else:
  from time import time as TimeStamp
print TimeStamp()
#---

This works for me as long as the clock rollover is ok and precision is
maintained.

Thanks,
Russ




More information about the Python-list mailing list