[pypy-svn] r23039 - pypy/dist/pypy/translator/microbench

ericvrp at codespeak.net ericvrp at codespeak.net
Sun Feb 5 15:26:10 CET 2006


Author: ericvrp
Date: Sun Feb  5 15:26:08 2006
New Revision: 23039

Modified:
   pypy/dist/pypy/translator/microbench/microbench.py
Log:
added -k ... option similar to py.test


Modified: pypy/dist/pypy/translator/microbench/microbench.py
==============================================================================
--- pypy/dist/pypy/translator/microbench/microbench.py	(original)
+++ pypy/dist/pypy/translator/microbench/microbench.py	Sun Feb  5 15:26:08 2006
@@ -14,11 +14,17 @@
     exec 'import ' + microbench
     microbenches.append(microbench)
 
-def run():
+def run(test_cases):
     MINIMUM_MICROBENCH_TIME = 1.0
 
     for microbench in microbenches:
         for k in [s for s in globals()[microbench].__dict__ if s.startswith('test_')] :
+            if test_cases:
+                for tc in test_cases:
+                    if k.startswith(tc):
+                        break
+                else:
+                    continue
             testcase = microbench + '.' + k + '()'
             start = time.clock()
             n = 0
@@ -30,9 +36,20 @@
             print '%s took %.2f seconds' % (testcase, duration / float(n))
 
 if __name__ == '__main__':
-    for n, exe in enumerate(sys.argv[1:]):
+    args = sys.argv[1:]
+    if '-k' in args:
+        i = args.index('-k')
+        executables = args[:i]
+        test_cases  = args[i+1:]
+        limit = '-k ' + ' '.join(test_cases)
+    else:
+        executables = args
+        test_cases  = []
+        limit = ''
+
+    for n, exe in enumerate(executables):
         print 'exe:', exe
-        data = [s for s in os.popen(exe + ' microbench.py 2>&1').readlines() if not s.startswith('debug:')]
+        data = [s for s in os.popen(exe + ' microbench.py %s 2>&1' % limit).readlines() if not s.startswith('debug:')]
         benchdata = {}
         for d in data:
             testcase, took, duration, seconds = d.split()
@@ -48,5 +65,5 @@
                 slowdown, testcase = r
                 print '%5.2fx slower on %s' % (slowdown, testcase)
         
-    if len(sys.argv) == 1:
-        run()
+    if not executables:
+        run(test_cases)



More information about the Pypy-commit mailing list