summaryrefslogtreecommitdiffstats
path: root/Tools/pybench
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-04-29 01:01:20 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-04-29 01:01:20 (GMT)
commitfe98e2fc8391607fc1cae235a49bbafc65a822f0 (patch)
treee00cb1f63634a8361ebd60c3a496a163e5d66c59 /Tools/pybench
parent47620a661128ce91f46f01fb46e1326880365e75 (diff)
downloadcpython-fe98e2fc8391607fc1cae235a49bbafc65a822f0.zip
cpython-fe98e2fc8391607fc1cae235a49bbafc65a822f0.tar.gz
cpython-fe98e2fc8391607fc1cae235a49bbafc65a822f0.tar.bz2
Issue #14428: Use the new time.perf_counter() and time.process_time() functions
* Replace "time.clock on windows, or time.time" with time.perf_counter() * profile module: only use time.process_time() instead of trying different functions providing the process time * timeit module: use time.perf_counter() by default, time.time() and time.clock() can still be used using --time and --clock options * pybench program: use time.perf_counter() by default, add support for the new time.process_time() and time.perf_counter() functions, but stay backward compatible. Use also time.get_clock_info() to display information of the timer.
Diffstat (limited to 'Tools/pybench')
-rwxr-xr-xTools/pybench/pybench.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Tools/pybench/pybench.py b/Tools/pybench/pybench.py
index cc1e55c..cac2ddf 100755
--- a/Tools/pybench/pybench.py
+++ b/Tools/pybench/pybench.py
@@ -73,11 +73,15 @@ ALLOW_SKIPPING_CALIBRATION = 1
# Timer types
TIMER_TIME_TIME = 'time.time'
+TIMER_TIME_PROCESS_TIME = 'time.process_time'
+TIMER_TIME_PERF_COUNTER = 'time.perf_counter'
TIMER_TIME_CLOCK = 'time.clock'
TIMER_SYSTIMES_PROCESSTIME = 'systimes.processtime'
# Choose platform default timer
-if sys.platform[:3] == 'win':
+if hasattr(time, 'perf_counter'):
+ TIMER_PLATFORM_DEFAULT = TIMER_TIME_PERF_COUNTER
+elif sys.platform[:3] == 'win':
# On WinXP this has 2.5ms resolution
TIMER_PLATFORM_DEFAULT = TIMER_TIME_CLOCK
else:
@@ -93,6 +97,10 @@ def get_timer(timertype):
if timertype == TIMER_TIME_TIME:
return time.time
+ elif timertype == TIMER_TIME_PROCESS_TIME:
+ return time.process_time
+ elif timertype == TIMER_TIME_PERF_COUNTER:
+ return time.perf_counter
elif timertype == TIMER_TIME_CLOCK:
return time.clock
elif timertype == TIMER_SYSTIMES_PROCESSTIME:
@@ -866,7 +874,18 @@ python pybench.py -s p25.pybench -c p21.pybench
print('* using timer: systimes.processtime (%s)' % \
systimes.SYSTIMES_IMPLEMENTATION)
else:
+ # Check that the clock function does exist
+ try:
+ get_timer(timer)
+ except TypeError:
+ print("* Error: Unknown timer: %s" % timer)
+ return
+
print('* using timer: %s' % timer)
+ if hasattr(time, 'get_clock_info'):
+ info = time.get_clock_info(timer[5:])
+ print('* timer: resolution=%s, implementation=%s'
+ % (info.resolution, info.implementation))
print()