[issue13481] Use an accurate clock in timeit
Charles-François Natali
report at bugs.python.org
Sat Nov 26 11:56:01 CET 2011
Charles-François Natali <neologix at free.fr> added the comment:
_clocks = ['CLOCK_PROCESS_CPUTIME_ID', 'CLOCK_MONOTONIC_RAW',
'CLOCK_MONOTONIC', 'CLOCK_REALTIME']
Beware, we're mixing CPU time and wall-clock time:
$ ./python -c "from time import *; id = CLOCK_REALTIME; t = clock_gettime(id); sleep(1); print(clock_gettime(id) - t)"
1.0011036396026611
$ ./python -c "from time import *; id = CLOCK_PROCESS_CPUTIME_ID; t = clock_gettime(id); sleep(1); print(clock_gettime(id) - t)"
9.480300000003217e-05
Right now, timeit measures wall-clock time:
"""
On either platform, the default timer functions measure wall clock time, not the CPU time. [...] On Unix, you can use clock() to measure CPU time.
"""
With CLOCK_PROCESS_CPUTIME_ID:
- depending on the platform, we'll measure either wall-clock time or CPU time
- preemtion, blocking syscalls, etc won't be accounted for (so, for example, I/O-related tests will be meaningless)
----------
nosy: +neologix
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13481>
_______________________________________
More information about the Python-bugs-list
mailing list