time.clock() rollover

John Arbash Meinel john at arbash-meinel.com
Tue Dec 18 20:38:45 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHaC/VJdeBCYSNAAMRAtMIAJ0bOkmdHRswy4HD1vf4iJfpHufxMQCfZLDG
KqtGZcjBt/I7WrQFCKLV8yw=
=8f9Y
-----END PGP SIGNATURE-----



More information about the bazaar mailing list