[Python-Dev] [RFC] PEP 418: Add monotonic time, performance counter and process time functions

Victor Stinner victor.stinner at gmail.com
Sun Apr 15 19:40:43 CEST 2012


2012/4/15 M.-A. Lemburg <mal at egenix.com>:
> I'd suggest to also include a tool or API to determine the
> real resolution of a time function (as opposed to the advertised
> one). See pybench's clockres.py helper as example.

The PEP includes such tool, but I forgot to mention it in the PEP:
http://hg.python.org/peps/file/tip/pep-0418/clock_precision.py

It is based on clockres.py from pybench. I used this tools to fill the
"Precision in Python" column of the different tables. The "Precision"
is the precision announced by the OS, whereas the "Precision in
Python" is the effictive precision in Python.

The full PEP includes results of different benchmarks: performance of
hardware clocks and performance of the different OS time functions.

> E.g. compare the results of clockres.py on Linux:
>
> Clock resolution of various timer implementations:
> time.clock:            10000.000us
> time.time:                 0.954us
> systimes.processtime:    999.000us
>
> and FreeBSD:
>
> Clock resolution of various timer implementations:
> time.clock:             7812.500us
> time.time:                 1.907us
> systimes.processtime:      1.000us

Cool, I found similar numbers :-)

> and Mac OS X:
>
> Clock resolution of various timer implementations:
> time.clock:                1.000us
> time.time:                 0.954us
> systimes.processtime:      1.000us

I will include these numbers on Mac OS X to the PEP.

> Regarding changing pybench:
> pybench has to stay backwards incompatible with
> earlier releases to make it possible to compare timings.
> You can add support for new timers to pybench, but please leave
> the existing timers and defaults in place.

I suppose that you are talking about this change:

-# Choose platform default timer
-if sys.platform[:3] == 'win':
-    # On WinXP this has 2.5ms resolution
-    TIMER_PLATFORM_DEFAULT = TIMER_TIME_CLOCK
-else:
-    # On Linux this has 1ms resolution
-    TIMER_PLATFORM_DEFAULT = TIMER_TIME_TIME
+TIMER_PLATFORM_DEFAULT = TIMER_TIME_PERF_COUNTER

from http://bugs.python.org/file25202/perf_counter_process_time.patch

It does not change the OS clock on Windows, only on Unix:
CLOCK_REALTIME (gettimeofday() for Python 3.2 and earlier) is replaced
with CLOCK_MONOTONIC. This change should only give a different result
if the system time is changed during the benchmark.

I'm ok to keep the default timer if you consider the change as incompatible.

Victor


More information about the Python-Dev mailing list