time.clock() rollover

Matt Nordhoff mnordhoff at mattnordhoff.com
Tue Dec 18 21:08:44 GMT 2007


John Arbash Meinel wrote:
> I've been trying to do some performance testing, and I'm getting a really weird
> result.
> 
> I believe I was told that "time.clock()" is the function one *should* use as it
> uses a high-performance clock. On Win32 it gives better resolution than
> time.time() and on Linux it gives CPU time rather than giving wall-clock time,
> which means it should be a bit more reproducible (if you are measuring CPU
> performance, at least).
> 
> Anyway, I ended up running into a problem with time.clock() rolling over.
> Specifically, I have:
> 
> t_start = time.clock()
> function()
> t_end = time.clock()
> 
> With values of:
> (Pdb) t_start
> 2136.3200000000002
> (Pdb) t_end
> -2138.557296
> 
> It at least looks like there is a 32-bit integer storing CPU time in
> microseconds, and that is overflowing. (2136 ~= 2**31/10**6)
> 
> Anyway, I just thought people should be aware of the overflow. It isn't hard to
> correct for, now that I know what is going on.

What about using timeit anyway?

Does it handle overflow?
-- 



More information about the bazaar mailing list