[pypy-svn] r67255 - in pypy/build/benchmark: . specific specific/test test

fijal at codespeak.net fijal at codespeak.net
Thu Aug 27 18:09:33 CEST 2009


Author: fijal
Date: Thu Aug 27 18:09:33 2009
New Revision: 67255

Added:
   pypy/build/benchmark/specific/richards.py   (contents, props changed)
Modified:
   pypy/build/benchmark/runner.py
   pypy/build/benchmark/specific/   (props changed)
   pypy/build/benchmark/specific/test/   (props changed)
   pypy/build/benchmark/specific/test/test_benchmarks.py
   pypy/build/benchmark/test/test_runner.py
Log:
Add richards, fixeol


Modified: pypy/build/benchmark/runner.py
==============================================================================
--- pypy/build/benchmark/runner.py	(original)
+++ pypy/build/benchmark/runner.py	Thu Aug 27 18:09:33 2009
@@ -24,6 +24,9 @@
         raise NotImplementedError("abstract base class")
 
 class ScriptRunner(AbstractRunner):
+    """ this benchmark runner executes script provided as a source code
+    """
+    
     tmpdir = None
     
     def __init__(self, name, source, executable=sys.executable):
@@ -37,10 +40,14 @@
             cls.tmpdir = udir.join('benchmark_runner')
             cls.tmpdir.ensure(dir=True)
 
-    def run_once(self):
+    def get_script_name(self):
         self.setup_tmpdir()
         fname = self.tmpdir.join(self.name + '.py')
         fname.write(self.source)
+        return fname
+
+    def run_once(self):
+        fname = self.get_script_name()
         pipe = subprocess.Popen([sys.executable, str(fname)],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
@@ -58,3 +65,12 @@
             raise OutputDidNotMatch("got %s" % output)
         return float(m.group(1))
 
+class ProgramRunner(ScriptRunner):
+    """ this benchmark runner executes an existing python script
+    """
+    def __init__(self, name, path):
+        self.path = path
+        self.name = name
+
+    def get_script_name(self):
+        return str(self.path)

Added: pypy/build/benchmark/specific/richards.py
==============================================================================
--- (empty file)
+++ pypy/build/benchmark/specific/richards.py	Thu Aug 27 18:09:33 2009
@@ -0,0 +1,17 @@
+
+import py
+import pypy
+import re
+from benchmark.runner import ProgramRunner, OutputDidNotMatch
+
+RICHARDS_PATH = ('..', 'translator', 'goal', 'richards.py')
+class RichardsRunner(ProgramRunner):
+    def __init__(self):
+        richards_fname = py.path.local(pypy.__file__).join(*RICHARDS_PATH)
+        ProgramRunner.__init__(self, 'richards', richards_fname)
+
+    def read_output(self, output):
+        m = re.search("Average time per iteration: ([\d.]+)", output)
+        if not m:
+            raise OutputDidNotMatch("got " + output)
+        return float(m.group(1))

Modified: pypy/build/benchmark/specific/test/test_benchmarks.py
==============================================================================
--- pypy/build/benchmark/specific/test/test_benchmarks.py	(original)
+++ pypy/build/benchmark/specific/test/test_benchmarks.py	Thu Aug 27 18:09:33 2009
@@ -1,7 +1,15 @@
 
 from benchmark.specific.pystone import PystoneRunner
+from benchmark.specific.richards import RichardsRunner
 
 def test_pystone():
     runner = PystoneRunner()
-    times = [runner.run(1)]
+    times = runner.run(1)
     assert len(times) == 1
+    assert isinstance(times[0], float)
+
+def test_richards():
+    runner = RichardsRunner()
+    times = runner.run(1)
+    assert len(times) == 1
+    assert isinstance(times[0], float)

Modified: pypy/build/benchmark/test/test_runner.py
==============================================================================
--- pypy/build/benchmark/test/test_runner.py	(original)
+++ pypy/build/benchmark/test/test_runner.py	Thu Aug 27 18:09:33 2009
@@ -1,6 +1,7 @@
 
 import py
-from benchmark.runner import ScriptRunner, ErrorExecuting
+from benchmark.runner import ScriptRunner, ErrorExecuting, ProgramRunner
+from pypy.tool.udir import udir
 
 class TestRunner(object):
     def test_script_runner(self):
@@ -16,3 +17,12 @@
     def test_script_runner_fail(self):
         runner = ScriptRunner("test3", "import sys; sys.exit(1)")
         py.test.raises(ErrorExecuting, runner.run)
+
+    def test_program_runner(self):
+        tmpdir = udir.join("benchmark_testdir")
+        tmpdir.ensure(dir=True)
+        f = tmpdir.join("xxx.py")
+        f.write("print 'time: 0'")
+        runner = ProgramRunner("test4", str(f))
+        t = runner.run(3)
+        assert t == [0, 0, 0]



More information about the Pypy-commit mailing list