Calculating Elapsed Time

Bengt Richter bokr at oz.net
Wed Dec 7 12:42:10 EST 2005


On Wed, 07 Dec 2005 16:35:15 -0000, Grant Edwards <grante at visi.com> wrote:

>On 2005-12-07, Peter Hansen <peter at engcorp.com> wrote:
>
>> 2. If your system returns figures after the decimal point, it
>>    probably has better resolution than one second (go figure).
>>    Depending on what system it is, your best bet to determine
>>    why is to check the documentation for your system (also go
>>    figure), since the details are not really handled by
>>    Python. Going by memory, Linux will generally be 1ms
>>    resolution (I might be off by 10 there...),
>
>In my experience, time.time() on Linux has a resolution of
>about 1us.  The delta I get when I do
>
>  print time.time()-time.time()
>
>is usually about 2-3us, but some of that is probably due to the
>overhead involved.
>
Try

 >>> import time
 >>> t=time.time; c=time.clock
 >>> min(filter(None,(-float.__sub__(c(),c()) for x in xrange(10000))    ))*1e3
 0.0058666657878347905
 >>> min(filter(None,(-float.__sub__(t(),t()) for x in xrange(10000))    ))*1e3
 9.9999904632568359

(This NT4 box is slow ;-)
BTW time.time is just the 100hz scheduling slice

 >>> min(filter(None,(-float.__sub__(t(),t()) for x in xrange(10000))    ))**-1
 100.00009536752259
 >>> min(filter(None,(-float.__sub__(t(),t()) for x in xrange(10000))    ))**-1
 100.00009536752259
 >>> min(filter(None,(-float.__sub__(c(),c()) for x in xrange(10000))    ))**-1
 149147.75106031806

Regards,
Bengt Richter



More information about the Python-list mailing list