calculating system clock resolution

jUrner at arcor.de jUrner at arcor.de
Sat Apr 8 07:16:20 EDT 2006


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

print calc_time_res()
>> 1.50203704834e-05

Something is going wrong here.
If you look at the function ,time.time() returns time in microseconds
(most oses and so
does mine).
So the calculation goes, lets say 1.23 - 1.24
How can the result be something like 1.50203704834e-05 ?
I would expect 0.01.

Next is, the first print statement prints out x and start equal up to
the fraction.

Is it Python giggeling?
Maybe it's python throwing the rounded float at us but internally
keeps calculating with the float returned by the os.
Maybe I'm wrong.




More information about the Python-list mailing list