Wraparound problems with time.clock() on Linux

Fernando Perez fperez528 at yahoo.com
Wed Apr 9 17:17:10 EDT 2003


Fernando Perez wrote:


> The problem I am having is that in certain long runs, I get negative
> values
> for the total() function.  I was wondering if there are wraparound issues
> I
> should be aware of.  Here is an example of the output from two different
> runs of my code:
[snip]
> This one, on the other hand, generated negative times.  I know (from
> timestamps on files made by the code as it ran), that the code took about
> 50 minutes of wall time to actually execute.  Since time.clock() is
> supposed to return floats, I wasn't expecting wraparound problems.

Sorry, scratch that.  I went looking further in the docs, and it seems that
time.clock() calls the system's clock(). From man clock:

       Note  that  the  time  can  wrap  around.   On  a  32bit  system 
where
       CLOCKS_PER_SEC  equals 1000000 this function will return the same
value
       approximately every 72 minutes.



Now, my code ran in less than 72 minutes, but it's possible that redhat
messed up the CLOCKS_PER_SEC  value so that the wraparound is hit before 72
minutes (half that, maybe?).  At any rate, now I know there _are_
wraparound issues.

Anyone know of a reliable way to time long-running codes?

Cheers,

f




More information about the Python-list mailing list