[pypy-commit] extradoc extradoc: improve runner

fijal noreply at buildbot.pypy.org
Tue Jun 14 21:35:46 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: extradoc
Changeset: r3678:f4487c623b92
Date: 2011-06-14 21:07 +0200
http://bitbucket.org/pypy/extradoc/changeset/f4487c623b92/

Log:	improve runner

diff --git a/talk/iwtc11/benchmarks/runner.py b/talk/iwtc11/benchmarks/runner.py
--- a/talk/iwtc11/benchmarks/runner.py
+++ b/talk/iwtc11/benchmarks/runner.py
@@ -2,6 +2,9 @@
 """ Usage:
 
 runner.py [-w warmup] [-n times] <file> <extra_args>
+
+Where extra_args is either what you pass to python file, if file ends with .py
+or a C compiler and it's options
 """
 
 from __future__ import division
@@ -10,13 +13,14 @@
 import sys
 import time
 from optparse import OptionParser
+import subprocess
 
 def main():
     parser = OptionParser()
     parser.add_option('-n', dest='no', help='number of iterations', type=int,
                       default=10)
     parser.add_option('-w', dest='warmup', help='number of warmup runs',
-                      type=int, default=0)
+                      type=int, default=3)
     options, args = parser.parse_args()
     if args[0].endswith('.py'):
         mod = py.path.local(args[0]).pyimport()
@@ -33,14 +37,29 @@
             mod.main(args)
             all.append(time.time() - t0)
             print >>sys.stderr, "Next:", all[-1]
+        name = mod.name
     else:
+        # not needed
+        options.warmup = 0
+        all = []
+        pipe = subprocess.Popen(args[1:] + [args[0]])
+        pipe.wait()
+        for i in range(options.no):
+            pipe = subprocess.Popen(['/usr/bin/time', '-f', '%e', './a.out'],
+                                     stderr=subprocess.PIPE,
+                                     stdout=subprocess.PIPE)
+            pipe.wait()
+            v = float(pipe.stderr.read().strip("\n"))
+            all.append(v)
+            print >>sys.stderr, "Next: %s" % (v,)
+        name = args[0].split(".")[0].split("/")[-1]
         
-    if n > 1:
+    if options.no > 1:
         avg = sum(all) / len(all)
         stddev = (sum([(i - avg) * (i - avg) for i in all]) / (len(all) - 1)) ** 0.5
-        print "Avg: %s +- %s" % (avg, stddev)
+        print "%s: %s +- %s" % (name, avg, stddev)
     else:
-        print "Run: %s" % (all[0],)
+        print "%s: %s" % (name, all[0])
 
 if __name__ == '__main__':
     main()
diff --git a/talk/iwtc11/benchmarks/sqrt/sqrt.py b/talk/iwtc11/benchmarks/sqrt/sqrt.py
--- a/talk/iwtc11/benchmarks/sqrt/sqrt.py
+++ b/talk/iwtc11/benchmarks/sqrt/sqrt.py
@@ -49,4 +49,6 @@
         return  Fix16((Fix16(other).val << 16) / self.val, False)
 
 def main(argv):
+    global name
+    name = 'sqrt_%s' % argv[0]
     sqrt(eval(argv[0])(123456), 100000000)
diff --git a/talk/iwtc11/benchmarks/sqrt/sqrt_double.c b/talk/iwtc11/benchmarks/sqrt/sqrt_double.c
--- a/talk/iwtc11/benchmarks/sqrt/sqrt_double.c
+++ b/talk/iwtc11/benchmarks/sqrt/sqrt_double.c
@@ -9,6 +9,5 @@
     x = (x + y/x) / 2.0;
   }
   printf("%f\n", x);
-  fprintf(stderr, "sqrt(float):   ");
   return 0;
 }


More information about the pypy-commit mailing list