[pypy-svn] r39723 - pypy/dist/pypy/translator/benchmark

mwh at codespeak.net mwh at codespeak.net
Fri Mar 2 17:35:04 CET 2007


Author: mwh
Date: Fri Mar  2 17:35:02 2007
New Revision: 39723

Modified:
   pypy/dist/pypy/translator/benchmark/bench-custom.py
   pypy/dist/pypy/translator/benchmark/benchmarks.py
Log:
add a docutils benchmark.
as this seems to require a svn docutils, you have to tell it where your
docutils svn checkout is, and some hair to allow benchmarks to refuse to run.


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	Fri Mar  2 17:35:02 2007
@@ -21,7 +21,13 @@
     else:
         benchmark_result = BenchmarkResultSet()
 
-    benchmarks = [b for b in BENCHMARKS if b.name in options.benchmarks]
+    benchmarks = []
+    for b in BENCHMARKS:
+        if b.name in options.benchmarks:
+            if not b.check():
+                print "can't run %s benchmark for some reason"%(b.name,)
+            else:
+                benchmarks.append(b)
 
     exes = get_executables(args)
     pythons = 'python2.5 python2.4 python2.3'.split()
@@ -59,9 +65,10 @@
 if __name__ == '__main__':
     from optparse import OptionParser
     parser = OptionParser()
+    default_benches = ','.join([b.name for b in BENCHMARKS if b.check()])
     parser.add_option(
         '--benchmarks', dest='benchmarks',
-        default=','.join([b.name for b in BENCHMARKS])
+        default=default_benches,
         )
     parser.add_option(
         '--pickle', dest='picklefile',

Modified: pypy/dist/pypy/translator/benchmark/benchmarks.py
==============================================================================
--- pypy/dist/pypy/translator/benchmark/benchmarks.py	(original)
+++ pypy/dist/pypy/translator/benchmark/benchmarks.py	Fri Mar  2 17:35:02 2007
@@ -20,11 +20,12 @@
     return float(line.split()[len(pattern.split())])
 
 class Benchmark(object):
-    def __init__(self, name, runner, asc_good, units):
+    def __init__(self, name, runner, asc_good, units, check=lambda:True):
         self.name = name
         self._run = runner
         self.asc_good = asc_good
         self.units = units
+        self.check = check
     def run(self, exe):
         try:
             return self._run(exe)
@@ -62,9 +63,39 @@
         raise BenchmarkFailed(status)
     return r
 
+def run_docutils(executable='/usr/local/bin/python'):
+    docutilssvnpathfile = py.magic.autopath().dirpath().join("docutilssvnpath")
+    docutilssvnpath = docutilssvnpathfile.read().strip()
+    translatetxt = py.magic.autopath().dirpath().dirpath().dirpath().join('doc').join('translation.txt')
+    command = """import sys
+sys.path[0:0] = ['%s', '%s/extras']
+from docutils.core import publish_cmdline
+publish_cmdline(writer_name='html')
+"""%(docutilssvnpath, docutilssvnpath)
+    T = time.time()
+    pid = os.fork()
+    if not pid:
+        davenull = os.open('/dev/null', os.O_RDWR)
+        os.dup2(davenull, 0)
+        os.dup2(davenull, 1)
+        os.dup2(davenull, 2)
+        status = os.spawnv(os.P_WAIT, executable, [executable, '-c', command, str(translatetxt)])
+        os._exit(status)
+    else:
+        status = os.waitpid(pid, 0)[1]
+    r = time.time() - T
+    if status:
+        raise BenchmarkFailed(status)
+    return r
+
+def check_docutils():
+    docutilssvnpathfile = py.magic.autopath().dirpath().join("docutilssvnpath")
+    return docutilssvnpathfile.check()
+
 BENCHMARKS = [Benchmark('richards', run_richards, RICHARDS_ASCENDING_GOOD, 'ms'),
               Benchmark('pystone', run_pystone, PYSTONE_ASCENDING_GOOD, ''),
               Benchmark('translate', run_translate, RICHARDS_ASCENDING_GOOD, 'ms'),
+              Benchmark('docutils', run_docutils, RICHARDS_ASCENDING_GOOD, 'ms', check_docutils),
              ]
 
 BENCHMARKS_BY_NAME = {}



More information about the Pypy-commit mailing list