summaryrefslogtreecommitdiff
path: root/Tools/pybench/pybench.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/pybench/pybench.py')
-rwxr-xr-xTools/pybench/pybench.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/Tools/pybench/pybench.py b/Tools/pybench/pybench.py
index 8eaad63cf1..cac2ddfb85 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:
@@ -107,6 +115,7 @@ def get_machine_details():
print('Getting machine details...')
buildno, builddate = platform.python_build()
python = platform.python_version()
+ # XXX this is now always UCS4, maybe replace it with 'PEP393' in 3.3+?
if sys.maxunicode == 65535:
# UCS2 build (standard)
unitype = 'UCS2'
@@ -865,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()