[Python-checkins] r46146 - sandbox/trunk/rjsh-pybench/pybench.py
steve.holden
python-checkins at python.org
Tue May 23 21:21:01 CEST 2006
Author: steve.holden
Date: Tue May 23 21:21:00 2006
New Revision: 46146
Modified:
sandbox/trunk/rjsh-pybench/pybench.py
Log:
Use the appropriate clock for the platform.
Default the number of calibration runs to 0 (can set with -C)
Modified: sandbox/trunk/rjsh-pybench/pybench.py
==============================================================================
--- sandbox/trunk/rjsh-pybench/pybench.py (original)
+++ sandbox/trunk/rjsh-pybench/pybench.py Tue May 23 21:21:00 2006
@@ -56,6 +56,13 @@
except ImportError:
import pickle
+if sys.platform == "win32":
+ # On Windows, the best timer is time.clock()
+ default_timer = time.clock
+else:
+ # On most other platforms the best timer is time.time()
+ default_timer = time.time
+
### Test baseclass
class Test:
@@ -108,7 +115,7 @@
# Misc. internal variables
last_timing = (0,0,0) # last timing (real,run,calibration)
warp = 1 # warp factor this test uses
- cruns = 20 # number of calibration runs
+ cruns = 0 # number of calibration runs
overhead = None # list of calibration timings
def __init__(self,warp=1):
@@ -133,16 +140,17 @@
"""
test = self.test
calibrate = self.calibrate
- clock = time.clock
+ clock = default_timer
cruns = self.cruns
# first calibrate
offset = 0.0
- for i in range(cruns):
- t = clock()
- calibrate()
- t = clock() - t
- offset = offset + t
- offset = offset / cruns
+ if cruns:
+ for i in range(cruns):
+ t = clock()
+ calibrate()
+ t = clock() - t
+ offset = offset + t
+ offset = offset / cruns
# now the real thing
t = clock()
test()
@@ -211,7 +219,6 @@
roundtime = 0 # Average round time
version = None # Benchmark version number (see __init__)
# as float x.yy
- starttime = None # Benchmark start time
def __init__(self):
@@ -250,7 +257,6 @@
clock = time.clock
print 'Running %i round(s) of the suite: ' % self.rounds
print
- self.starttime = time.time()
roundtime = clock()
for i in range(self.rounds):
if verbose:
@@ -323,7 +329,7 @@
print '-'*77
if compatible and compare_to.roundtime > 0 and \
compare_to.version == self.version:
- print '%30s: %8.2f ms %8.2f ms %+7.2f%%' % \
+ print '%30s: %8.2f ms %8.2f ms %+7.2f%%' % \
('Notional minimum round time', totalmintime * 1000.0,
other_totalmintime * 1000.0,
((totalmintime*self.warp)/
@@ -365,7 +371,8 @@
SwitchOption('--no-gc','disable garbage collection', 0),
SwitchOption('--no-syscheck',
'"disable" sys check interval (set to sys.maxint)', 0),
- ArgumentOption('-t', 'tests containing substring', '')
+ ArgumentOption('-t', 'tests containing substring', ''),
+ ArgumentOption('-C', 'number of calibration runs (default 0)', '')
]
about = """\
More information about the Python-checkins
mailing list