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

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Dec 21 16:40:35 CET 2005


Author: ericvrp
Date: Wed Dec 21 16:40:34 2005
New Revision: 21421

Added:
   pypy/dist/pypy/translator/microbench/
   pypy/dist/pypy/translator/microbench/microbench.py   (contents, props changed)
   pypy/dist/pypy/translator/microbench/test_count1.py
   pypy/dist/pypy/translator/microbench/test_create1.py
Log:
basic framework to stuff our micro benchmarks into


Added: pypy/dist/pypy/translator/microbench/microbench.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/microbench/microbench.py	Wed Dec 21 16:40:34 2005
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+import os, time, sys
+
+microbenches = []
+for fname in os.listdir('.'):
+    if not fname.startswith('test_') or not fname.endswith('.py'):
+        continue
+    microbench = fname[:-3]
+    exec 'import ' + microbench
+    microbenches.append(microbench)
+
+def run():
+    MINIMUM_MICROBENCH_TIME = 2.5
+
+    for microbench in microbenches:
+        for k in [s for s in globals()[microbench].__dict__ if s.startswith('test_')] :
+            testcase = microbench + '.' + k + '()'
+            start = time.clock()
+            n = 0
+            duration = 0.0
+            while duration < MINIMUM_MICROBENCH_TIME:
+                exec testcase
+                n += 1
+                duration = time.clock() - start
+            print '%s took %.2f seconds' % (testcase, duration / float(n))
+
+if __name__ == '__main__':
+    for n, exe in enumerate(sys.argv[1:3]):
+        print 'exe:', exe
+        data = [s for s in os.popen(exe + ' microbench.py 2>&1').readlines() if not s.startswith('debug:')]
+        benchdata = {}
+        for d in data:
+            testcase, took, duration, seconds = d.split()
+            benchdata[testcase] = float(duration)
+        if n == 0:
+            benchdata_ref = benchdata
+        else:
+            for k, v in benchdata.iteritems():
+                print '%s %.2fx slower' % (k, v / benchdata_ref[k])
+        
+    if len(sys.argv) == 1:
+        run()

Added: pypy/dist/pypy/translator/microbench/test_count1.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/microbench/test_count1.py	Wed Dec 21 16:40:34 2005
@@ -0,0 +1,19 @@
+N = int(2**19 - 1)
+
+def test_loop():
+    x = 0
+    n = N
+    while x < n:
+        x = x + 1
+
+#
+def plus1(x):
+    return x + 1
+
+def test_call_function():
+    x = 0
+    n = N
+    while x < n:
+        x = plus1(x) 
+
+#

Added: pypy/dist/pypy/translator/microbench/test_create1.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/microbench/test_create1.py	Wed Dec 21 16:40:34 2005
@@ -0,0 +1,15 @@
+LOOPS = 1 << 18
+
+class Foo:
+    pass
+
+def test_simple_loop():
+    i = 0
+    while i < LOOPS:
+        i += 1
+
+def test_simple_loop_with_class_creation():
+    i = 0
+    while i < LOOPS:
+        Foo()
+        i += 1



More information about the Pypy-commit mailing list