Commit f8458777 authored by Steve Holden's avatar Steve Holden

Use minimum calibration time rather than avergae to avoid

the illusion of negative run times. Halt with an error if
run times go below 10 ms, indicating that results will be
unreliable.
parent 3a65d87e
...@@ -126,7 +126,7 @@ class Test: ...@@ -126,7 +126,7 @@ class Test:
self.operations = self.operations self.operations = self.operations
self.rounds = self.rounds self.rounds = self.rounds
def run(self): def run(self, cruns):
""" Run the test in two phases: first calibrate, then """ Run the test in two phases: first calibrate, then
do the actual test. Be careful to keep the calibration do the actual test. Be careful to keep the calibration
...@@ -136,20 +136,23 @@ class Test: ...@@ -136,20 +136,23 @@ class Test:
test = self.test test = self.test
calibrate = self.calibrate calibrate = self.calibrate
clock = time.clock clock = time.clock
cruns = self.cruns
# first calibrate # first calibrate
offset = 0.0 t = clock()
calibrate()
offset = clock() - t
if cruns: if cruns:
for i in range(cruns): for i in range(cruns-1):
t = clock() t = clock()
calibrate() calibrate()
t = clock() - t t = clock() - t
offset = offset + t if t < offset:
offset = offset / cruns offset = t
# now the real thing # now the real thing
t = clock() t = clock()
test() test()
t = clock() - t t = clock() - t
if t < 0.01:
sys.exit("Lower warp required: test times < 10 ms are unreliable")
self.last_timing = (t-offset,t,offset) self.last_timing = (t-offset,t,offset)
self.times.append(t-offset) self.times.append(t-offset)
...@@ -253,7 +256,7 @@ class Benchmark: ...@@ -253,7 +256,7 @@ class Benchmark:
print len(l), "tests found" print len(l), "tests found"
print print
def run(self, verbose): def run(self, verbose, cruns):
tests = self.tests.items() tests = self.tests.items()
tests.sort() tests.sort()
...@@ -266,10 +269,10 @@ class Benchmark: ...@@ -266,10 +269,10 @@ class Benchmark:
if verbose: if verbose:
print ' Round %-25i real abs overhead' % (i+1) print ' Round %-25i real abs overhead' % (i+1)
for j in range(len(tests)): for j in range(len(tests)):
name,t = tests[j] name, t = tests[j]
if verbose: if verbose:
print '%30s:' % name, print '%30s:' % name,
t.run() t.run(cruns)
if verbose: if verbose:
print ' %.3fr %.3fa %.3fo' % t.last_timing print ' %.3fr %.3fa %.3fo' % t.last_timing
if verbose: if verbose:
...@@ -379,7 +382,7 @@ class PyBenchCmdline(Application): ...@@ -379,7 +382,7 @@ class PyBenchCmdline(Application):
SwitchOption('--no-syscheck', SwitchOption('--no-syscheck',
'"disable" sys check interval (set to sys.maxint)', 0), '"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)', '') ArgumentOption('-C', 'number of calibration runs (default 20)', 20)
] ]
about = """\ about = """\
...@@ -423,6 +426,8 @@ python pybench.py -s p15 -c p14 ...@@ -423,6 +426,8 @@ python pybench.py -s p15 -c p14
limitnames = self.values['-t'] limitnames = self.values['-t']
verbose = self.verbose verbose = self.verbose
nosyscheck = self.values['--no-syscheck'] nosyscheck = self.values['--no-syscheck']
cruns = self.values['-C']
print "CRUNS:", cruns
print 'PYBENCH',__version__ print 'PYBENCH',__version__
...@@ -488,7 +493,7 @@ python pybench.py -s p15 -c p14 ...@@ -488,7 +493,7 @@ python pybench.py -s p15 -c p14
bench.rounds = rounds bench.rounds = rounds
bench.load_tests(Setup, warp, limitnames, verbose) bench.load_tests(Setup, warp, limitnames, verbose)
try: try:
bench.run(verbose) bench.run(verbose, cruns)
except KeyboardInterrupt: except KeyboardInterrupt:
print print
print '*** KeyboardInterrupt -- Aborting' print '*** KeyboardInterrupt -- Aborting'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment