Wraparound problems with time.clock() on Linux

Fernando Perez fperez528 at yahoo.com
Wed Apr 9 20:18:24 EDT 2003


Carsten Gaebler wrote:

> In article <b722km$bau$2 at peabody.colorado.edu>, Fernando Perez wrote:
>> 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.
>> 
>> 
> 
>> Anyone know of a reliable way to time long-running codes?
> 
> Without having tested it for more than 72 minutes, I'd try
> resource.getrusage().

Thanks for the tip.  I'll give it a shot.  It still has 32-bit issues with
time_t shoved in there, but hopefully the CLOCKS_PER_SEC  factor won't kill
me quite so early.

OTOH, getrusage() isn't nearly as user-friendly as a simple clock() call.
Bummer :(

Cheers,

f.




More information about the Python-list mailing list