calculating system clock resolution

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Apr 8 03:46:17 EDT 2006


On Fri, 07 Apr 2006 16:39:40 -0700, jUrner wrote:

> Maybe it was not too clear what I was trying to point out.
> 
> I have to calculate the time time.time() requires to return the next
> tick of the clock.
> Should be about 0.01ms but this may differ from os to os.

I suspect that Python isn't quite fast enough to give an accurate measure
for this, but I could be wrong.

You can try this:

def calc_time_res():
    now = time.time
    start = now()
    x = start
    while start == x:
        x = now()
    print x - start

Trying it, I get a fairly small number:




>>> calc_time_res()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in calc_time_res
NameError: global name 'time' is not defined
>>> import time
>>>
>>> calc_time_res()
2.50339508057e-05
>>> calc_time_res()
2.59876251221e-05
>>> calc_time_res()
2.59876251221e-05
>>> calc_time_res()
2.59876251221e-05
>>> calc_time_res()
2.40802764893e-05









> 
> BTW (I'm new to linux) cat  /proc/cpuinfo is nice but I have 2457.60
> bogomips.
> Is this something i should be concerned about? I mean is this
> contageous or something ;-)




More information about the Python-list mailing list