[pypy-svn] r35916 - in pypy/dist/pypy/translator/benchmark: . test
mwh at codespeak.net
mwh at codespeak.net
Wed Dec 20 13:39:01 CET 2006
Author: mwh
Date: Wed Dec 20 13:38:56 2006
New Revision: 35916
Added:
pypy/dist/pypy/translator/benchmark/result.py (contents, props changed)
pypy/dist/pypy/translator/benchmark/test/
pypy/dist/pypy/translator/benchmark/test/__init__.py (contents, props changed)
pypy/dist/pypy/translator/benchmark/test/test_result.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/benchmark/bench-custom.py
Log:
move the BenchmarkResult class into its own file (so it's not always pickled
as __main__.BenchmarkResult...) and add a simple test.
Modified: pypy/dist/pypy/translator/benchmark/bench-custom.py
==============================================================================
--- pypy/dist/pypy/translator/benchmark/bench-custom.py (original)
+++ pypy/dist/pypy/translator/benchmark/bench-custom.py Wed Dec 20 13:38:56 2006
@@ -1,7 +1,7 @@
# benchmarks on a unix machine.
-# to be executed in the goal folder,
-# where a couple of pypy-* files is expected.
+import autopath
+from pypy.translator.benchmark.result import BenchmarkResult
import os, sys, time, pickle, re
PYSTONE_CMD = 'from test import pystone;pystone.main(%s)'
@@ -12,55 +12,12 @@
RICHARDS_PATTERN = 'Average time per iteration:'
RICHARDS_ASCENDING_GOOD = False
-class BenchmarkResult(object):
-
- def __init__(self, filename, max_results=10):
- self.filename = filename
- self.max_results = max_results
- if os.path.exists(filename):
- f = open(filename, 'r')
- self.n_results = pickle.load(f)
- self.best_result = pickle.load(f)
- f.close()
- # any exception while loading the file is best reported
- # as a crash, instead of as a silent loss of all the
- # data :-/
- else:
- self.n_results = {}
- self.best_result = {}
-
- def is_stable(self, name):
- try:
- return self.n_results[name] >= self.max_results
- except:
- return False
-
- def update(self, name, result, ascending_good):
- try:
- if ascending_good:
- self.best_result[name] = max(self.best_result[name], result)
- else:
- self.best_result[name] = min(self.best_result[name], result)
- except KeyError:
- self.n_results[name] = 0
- self.best_result[name] = result
- self.n_results[name] += 1
-
- f = open(self.filename, 'w')
- pickle.dump(self.n_results , f)
- pickle.dump(self.best_result, f)
- f.close()
-
- def get_best_result(self, name):
- return self.best_result[name]
-
-
def get_result(txt, pattern):
for line in txt.split('\n'):
if line.startswith(pattern):
break
else:
- print 'warning: this is no valid output'
+ print 'warning: this is not valid output'
return 99999.0
return float(line.split()[len(pattern.split())])
Added: pypy/dist/pypy/translator/benchmark/result.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/benchmark/result.py Wed Dec 20 13:38:56 2006
@@ -0,0 +1,44 @@
+import os, pickle
+
+class BenchmarkResult(object):
+
+ def __init__(self, filename, max_results=10):
+ self.filename = filename
+ self.max_results = max_results
+ if os.path.exists(filename):
+ f = open(filename, 'r')
+ self.n_results = pickle.load(f)
+ self.best_result = pickle.load(f)
+ f.close()
+ # any exception while loading the file is best reported
+ # as a crash, instead of as a silent loss of all the
+ # data :-/
+ else:
+ self.n_results = {}
+ self.best_result = {}
+
+ def is_stable(self, name):
+ try:
+ return self.n_results[name] >= self.max_results
+ except:
+ return False
+
+ def update(self, name, result, ascending_good):
+ try:
+ if ascending_good:
+ self.best_result[name] = max(self.best_result[name], result)
+ else:
+ self.best_result[name] = min(self.best_result[name], result)
+ except KeyError:
+ self.n_results[name] = 0
+ self.best_result[name] = result
+ self.n_results[name] += 1
+
+ f = open(self.filename, 'w')
+ pickle.dump(self.n_results , f)
+ pickle.dump(self.best_result, f)
+ f.close()
+
+ def get_best_result(self, name):
+ return self.best_result[name]
+
Added: pypy/dist/pypy/translator/benchmark/test/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/benchmark/test/__init__.py Wed Dec 20 13:38:56 2006
@@ -0,0 +1 @@
+#
Added: pypy/dist/pypy/translator/benchmark/test/test_result.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/benchmark/test/test_result.py Wed Dec 20 13:38:56 2006
@@ -0,0 +1,19 @@
+import py
+from pypy.translator.benchmark import result
+
+temp = py.test.ensuretemp("report")
+
+def test_simple():
+ fname = temp.join("simple")
+ b = result.BenchmarkResult(str(fname), 3)
+
+ b.update('foo', 1, True)
+ assert b.get_best_result('foo') == 1
+
+ b.update('foo', 2, True)
+ assert b.get_best_result('foo') == 2
+ assert not b.is_stable('foo')
+
+ b.update('foo', 1, True)
+ assert b.get_best_result('foo') == 2
+ assert b.is_stable('foo')
More information about the Pypy-commit
mailing list