Calculating Elapsed Time
Grant Edwards
grante at visi.com
Wed Dec 7 12:03:38 EST 2005
On 2005-12-07, Grant Edwards <grante at visi.com> wrote:
>> if I run this on the Windows 2K box I'm sitting at right now, it settles
>> at 100 for time.time, and 1789772 for time.clock. on linux, I get 100
>> for time.clock instead, and 262144 for time.time.
>
> At least under Linux, I suspect you're just measuring loop time
> rather than the granularity of the time measurement. I don't
> know which library call the time modules uses, but if it's
> gettimeofday(), that is limited to 1us resolution.
> clock_gettime() provides an API with 1ns resolution. Not sure
> what the actual data resolution is...
Depending on which clock is used, the resolution of
clock_gettime() appears to be as low as 1ns. I usually get
deltas of 136ns when calling clock_gettime() using CLOCK_PROCESS_CPUTIME_ID.
I suspect the function/system call overhead is larger than the
clock resolution.
IIRC, time.time() uses gettimeofday() under Linux, so you can
expect 1us resolution.
--
Grant Edwards grante Yow! I want to kill
at everyone here with a cute
visi.com colorful Hydrogen Bomb!!
More information about the Python-list
mailing list