calling functions at the same time

Peter Hansen peter at engcorp.com
Sat May 1 15:06:41 EDT 2004


Grant Edwards wrote:

> In article <r4idnSA-J8HtSw7dRVn-hQ at powergate.ca>, Peter Hansen wrote:
(Someone else wrote this first part, then Grant's reply, then mine)
>>>>You can't get greater then 1ms accuracy when measuring a time
>>>>on todays machines, and that will be less when measuring time
>>>>over a network...
>>>
>>>Not sure what you mean by "todays machines", but on a
>>>Pentium-class machine running Linux, you get approx 1us
>>>resolution with calls to time.time():
>>
>>Keep in mind the difference between "accuracy" and
>>"resolution" (or "precision").
> 
> I do.
> 
> Not only do you get 1us resolution, you get packet timestamp
> _accuracy_ to well under 1ms according to tests I've run 
> comparing packet timestamps against an oscilloscope trace.

[snip other technical details]

> As soon as there are other ready tasks, the accuracy of the
> measurement quickly deteriorates to tens of millisconds due to
> scheduling latencies.

The last sentence is really the whole point.  The OP needs
to be aware that the accuracy *cannot* be *guaranteed*
to better than "tens of milliseconds", overall, regardless
of the "accuracy" of the clock tick or the resolution of
anything...

The notes on timeit.py are helpful in this respect, however:
taking the shortest result of repeated measurements is a
pretty good way to get an "accurate" number, most of the
time.  The other, higher results represent the interference
of all those other tasks which will tend to run as you
try to take measurements.

-Peter



More information about the Python-list mailing list