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

mwh at codespeak.net mwh at codespeak.net
Thu Jan 4 13:01:57 CET 2007


Author: mwh
Date: Thu Jan  4 13:01:52 2007
New Revision: 36145

Added:
   pypy/dist/pypy/translator/benchmark/benchmarks.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/benchmark/bench-custom.py
Log:
sundry improvements to bench-custom and related stuff:
move benchmark definitions to a separate file
allow benchmarks to run when not run from the goal directory.


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	Thu Jan  4 13:01:52 2007
@@ -2,69 +2,23 @@
 
 import autopath
 from pypy.translator.benchmark.result import BenchmarkResult
+from pypy.translator.benchmark.benchmarks import BENCHMARKS
 import os, sys, time, pickle, re
 
-PYSTONE_CMD = 'from test import pystone;pystone.main(%s)'
-PYSTONE_PATTERN = 'This machine benchmarks at'
-PYSTONE_ASCENDING_GOOD = True
-
-RICHARDS_CMD = 'from richards import *;main(iterations=%d)'
-RICHARDS_PATTERN = 'Average time per iteration:'
-RICHARDS_ASCENDING_GOOD = False
-
-def get_result(txt, pattern):
-    for line in txt.split('\n'):
-        if line.startswith(pattern):
-            break
-    else:
-        print 'warning: this is not valid output'
-        return 99999.0
-    return float(line.split()[len(pattern.split())])
-
-def run_cmd(cmd):
-    #print "running", cmd
-    pipe = os.popen(cmd + ' 2>&1')
-    return pipe.read()
-
-def run_pystone(executable='/usr/local/bin/python', n=0):
-    argstr = PYSTONE_CMD % (str(n) and n or '')
-    txt = run_cmd('"%s" -c "%s"' % (executable, argstr))
-    return get_result(txt, PYSTONE_PATTERN)
-
-def run_richards(executable='/usr/local/bin/python', n=5):
-    argstr = RICHARDS_CMD % n
-    txt = run_cmd('"%s" -c "%s"' % (executable, argstr))
-    return get_result(txt, RICHARDS_PATTERN)
-
-def run_translate(executable='/usr/local/bin/python'):
-    argstr = 'sh -c "time %s translate.py --text --batch --backendopt --no-compile targetrpystonedalone.py > /dev/null 2>/dev/null" 2>&1 | grep real'
-    txt = run_cmd(argstr%executable)
-    m = re.match('real\s+(?P<mins>\\d+)m(?P<secs>\\d+\\.\\d+)s', txt)
-    if not m:
-       print repr(txt)
-       print 'ow'
-       return 99999.0
-    return 1000*(float(m.group('mins'))*60 + float(m.group('secs')))
-
-BENCHMARKS = [('richards', run_richards, RICHARDS_ASCENDING_GOOD, 'ms'),
-              ('pystone', run_pystone, PYSTONE_ASCENDING_GOOD, ''),
-              ('translate', run_translate, RICHARDS_ASCENDING_GOOD, 'ms'),
-             ]
+def get_executables(args):  #sorted by revision number (highest first)
+    return sorted(args, key=os.path.getmtime)
 
-def get_executables():  #sorted by revision number (highest first)
-    return sorted(sys.argv[1:], key=os.path.getmtime)
-
-def main():
+def main(options, args):
     benchmark_result = BenchmarkResult('bench-custom.benchmark_result')
 
-    ref_rich, ref_stone = None, None
+    benchmarks = [b for b in BENCHMARKS if b[0] in options.benchmarks]
 
-    exes = get_executables()
+    exes = get_executables(args)
     pythons = 'python2.4 python2.3'.split()
     width = max(map(len, exes+pythons+['executable'])) + 3
 
     print 'date                           size codesize    %-*s'%(width, 'executable'),
-    for name, run, ascgood, units in BENCHMARKS:
+    for name, run, ascgood, units in benchmarks:
         print '    %-*s'%(6+len(units)+2+8+2-4, name),
     print
     sys.stdout.flush()
@@ -84,7 +38,7 @@
                 exe_ = './' + exe
         print '%-26s %8s %8s    %-*s'%(ctime, size, codesize, width, exe),
         sys.stdout.flush()
-        for name, run, ascgood, units in BENCHMARKS:
+        for name, run, ascgood, units in benchmarks:
             n = exe + '_' + name
             if not benchmark_result.is_stable(n):
                 benchmark_result.update(n, run(exe_), ascgood)
@@ -101,4 +55,11 @@
         sys.stdout.flush()
 
 if __name__ == '__main__':
-    main()
+    from optparse import OptionParser
+    parser = OptionParser()
+    parser.add_option(
+        '--benchmarks', dest='benchmarks',
+        default=','.join([b[0] for b in BENCHMARKS])
+        )
+    options, args = parser.parse_args(sys.argv[1:])
+    main(options, args)

Added: pypy/dist/pypy/translator/benchmark/benchmarks.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/benchmark/benchmarks.py	Thu Jan  4 13:01:52 2007
@@ -0,0 +1,56 @@
+import os, sys, time, pickle, re, py
+
+PYSTONE_CMD = 'from test import pystone;pystone.main(%s)'
+PYSTONE_PATTERN = 'This machine benchmarks at'
+PYSTONE_ASCENDING_GOOD = True
+
+RICHARDS_CMD = 'from richards import *;main(iterations=%d)'
+RICHARDS_PATTERN = 'Average time per iteration:'
+RICHARDS_ASCENDING_GOOD = False
+
+def get_result(txt, pattern):
+    for line in txt.split('\n'):
+        if line.startswith(pattern):
+            break
+    else:
+        print repr(txt)
+        print 'warning: this is not valid output'
+        return 99999.0
+    return float(line.split()[len(pattern.split())])
+
+def run_cmd(cmd):
+    #print "running", cmd
+    pipe = os.popen(cmd + ' 2>&1')
+    r = pipe.read()
+    status = pipe.close()
+    if status:
+        print "warning: %r had exit status %s"%(cmd, status)
+    return r
+
+def run_pystone(executable='/usr/local/bin/python', n=''):
+    distdir = py.magic.autopath().dirpath().dirpath().dirpath().dirpath()
+    pystone = distdir.join('lib-python').join('2.4.1').join('test').join('pystone.py')
+    txt = run_cmd('"%s" "%s" %s' % (executable, pystone, n))
+    return get_result(txt, PYSTONE_PATTERN)
+
+def run_richards(executable='/usr/local/bin/python', n=5):
+    richards = py.magic.autopath().dirpath().dirpath().join('goal').join('richards.py')
+    txt = run_cmd('"%s" %s %s' % (executable, richards, n))
+    return get_result(txt, RICHARDS_PATTERN)
+
+def run_translate(executable='/usr/local/bin/python'):
+    translate = py.magic.autopath().dirpath().dirpath().join('goal').join('translate.py')
+    argstr = 'sh -c "time %s %s --text --batch --backendopt --no-compile targetrpystonedalone.py > /dev/null 2>/dev/null" 2>&1 | grep real'
+    cmd = argstr%(executable, translate)
+    txt = run_cmd(cmd)
+    m = re.match('real\s+(?P<mins>\\d+)m(?P<secs>\\d+\\.\\d+)s', txt)
+    if not m:
+       print repr(txt)
+       print 'ow'
+       return 99999.0
+    return 1000*(float(m.group('mins'))*60 + float(m.group('secs')))
+
+BENCHMARKS = [('richards', run_richards, RICHARDS_ASCENDING_GOOD, 'ms'),
+              ('pystone', run_pystone, PYSTONE_ASCENDING_GOOD, ''),
+              ('translate', run_translate, RICHARDS_ASCENDING_GOOD, 'ms'),
+             ]



More information about the Pypy-commit mailing list