[pypy-svn] r50555 - pypy/dist/pypy/rpython/microbench

atobe at codespeak.net atobe at codespeak.net
Sun Jan 13 15:36:22 CET 2008


Author: atobe
Date: Sun Jan 13 15:36:22 2008
New Revision: 50555

Modified:
   pypy/dist/pypy/rpython/microbench/microbench.py
Log:
Added microbenchmarks for JVM

Modified: pypy/dist/pypy/rpython/microbench/microbench.py
==============================================================================
--- pypy/dist/pypy/rpython/microbench/microbench.py	(original)
+++ pypy/dist/pypy/rpython/microbench/microbench.py	Sun Jan 13 15:36:22 2008
@@ -35,14 +35,16 @@
 
 def run_benchmark(exe):
     from pypy.translator.cli.test.runtest import CliFunctionWrapper
-    if isinstance(exe, CliFunctionWrapper):
+    from pypy.translator.jvm.test.runtest import JvmGeneratedSourceWrapper
+    
+    if exe.__class__ in [CliFunctionWrapper,JvmGeneratedSourceWrapper]:
         stdout, stderr, retval = exe.run()
     else:
         assert isinstance(exe, str)
         bench = subprocess.Popen(exe, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         stdout, stderr = bench.communicate()
         retval = bench.wait()
-
+    
     if retval != 0:
         print 'Running benchmark failed'
         print 'Standard Output:'
@@ -51,7 +53,7 @@
         print 'Standard Error:'
         print stderr
         raise SystemExit(-1)
-
+    
     mydict = {}
     for line in stdout.splitlines():
         name, res = line.split(':')
@@ -66,7 +68,7 @@
         for module in glob('*.py'):
             if module not in ('__init__.py', 'autopath.py', 'microbench.py'):
                 modules.append(module)
-
+    
     for module in modules:
         module = module.rstrip('.py')
         exec 'from %s import *' % module in globals()
@@ -83,25 +85,33 @@
         for name, func in benchmarks:
             print name, ':', func()
         return 0
-
+    
     t = Translation(entry_point, standalone=True, backend='c')
     c_exe = t.compile()
     t = Translation(entry_point, standalone=True, backend='cli')
     cli_exe = t.compile()
-
+    t = Translation(entry_point, standalone=True, backend='jvm')
+    jvm_exe = t.compile()
+  
     c_res = run_benchmark(c_exe)
     cli_res = run_benchmark(cli_exe)
-
-    print 'benchmark                              genc     gencli       ratio'
+    jvm_res = run_benchmark(jvm_exe)
+    
+    print 'benchmark                              genc     gencli     cli_ratio   genjvm     jvm_ratio'
     print
     for name, _ in benchmarks:
         c_time = c_res[name]
         cli_time = cli_res[name]
+        jvm_time = jvm_res[name]
+        if c_time == 0:
+            cli_ratio = '%10s' % '---'
+        else:
+            cli_ratio = '%10.2f' % (cli_time/c_time)
         if c_time == 0:
-            ratio = '%10s' % '---'
+            jvm_ratio = '%10s' % '---'
         else:
-            ratio = '%10.2f' % (cli_time/c_time)
-        print '%-32s %10.2f %10.2f %s' % (name, c_time, cli_time, ratio)
+            jvm_ratio = '%10.2f' % (jvm_time/c_time)
+        print '%-32s %10.2f %10.2f %s %10.2f %s' % (name, c_time, cli_time, cli_ratio, jvm_time, jvm_ratio)
 
 if __name__ == '__main__':
     main()



More information about the Pypy-commit mailing list