[pypy-svn] r56898 - pypy/dist/pypy/interpreter/callbench

pedronis at codespeak.net pedronis at codespeak.net
Fri Aug 1 19:20:09 CEST 2008


Author: pedronis
Date: Fri Aug  1 19:20:08 2008
New Revision: 56898

Added:
   pypy/dist/pypy/interpreter/callbench/
   pypy/dist/pypy/interpreter/callbench/bltn04.py
   pypy/dist/pypy/interpreter/callbench/bltna1.py
   pypy/dist/pypy/interpreter/callbench/bm14.py
   pypy/dist/pypy/interpreter/callbench/bmabvararg.py
   pypy/dist/pypy/interpreter/callbench/bmfilter.py
   pypy/dist/pypy/interpreter/callbench/bmmore.py
   pypy/dist/pypy/interpreter/callbench/compare.py
   pypy/dist/pypy/interpreter/callbench/f04.py
   pypy/dist/pypy/interpreter/callbench/fabvararg.py
   pypy/dist/pypy/interpreter/callbench/ffilter.py
   pypy/dist/pypy/interpreter/callbench/ffunccall.py
   pypy/dist/pypy/interpreter/callbench/fmore.py
   pypy/dist/pypy/interpreter/callbench/inst.py
   pypy/dist/pypy/interpreter/callbench/instcall.py
   pypy/dist/pypy/interpreter/callbench/sup.py
Log:
a set of benchmarks that exercizes the code paths for calls, in particular most of the current shortcuts and interesting cases



Added: pypy/dist/pypy/interpreter/callbench/bltn04.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/bltn04.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,40 @@
+from sup import run
+
+def w(N, start):
+    c = chr
+
+    start()
+    i = 0
+    while i < N:
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)        
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)        
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)
+        c(65)        
+        i+=1
+
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/bltna1.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/bltna1.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,22 @@
+from sup import run
+
+def w(N, start):
+    o = object
+    start()
+    i = 0
+    while i < N:
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()
+        o()        
+        i+=1
+    
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/bm14.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/bm14.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,51 @@
+from sup import run
+
+def w(N, start):
+    class A(object):
+        def f0(self):
+            pass
+        def f1(self, a):
+            pass
+        def f2(self, a, b):
+            pass
+        def f3(self, a, b, c):
+            pass
+        def f4(self, a, b, c, d):
+            pass
+
+    a = A()
+    f0 = a.f0
+    f1 = a.f1
+    f2 = a.f2
+    f3 = a.f3
+    f4 = a.f4
+
+    start()
+    i = 0
+    while i < N:
+        f0()
+        f0()
+        f0()
+        f0()
+        f1(1)
+        f1(1)
+        f1(1)
+        f1(1)
+        f2(1, 2)
+        f2(1, 2)
+        f2(1, 2)
+        f3(1, 2, 3)
+        f3(1, 2, 3)
+        f4(1, 2, 3, 4)
+
+        f0()
+        f0()
+        f0()
+        f1(1)
+        f1(1)
+        f1(1)
+        f2(1, 2)
+        
+        i+=1
+
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/bmabvararg.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/bmabvararg.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,29 @@
+from sup import run
+
+def w(N, start):
+    class A(object):
+        def f(self, a, b, *args):
+            pass
+
+    a = A()
+    f = a.f
+    z = (3, 4, 5)
+
+    start()
+    i = 0
+    while i < N:
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        i+=1
+
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/bmfilter.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/bmfilter.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,20 @@
+from sup import run
+
+def w(N, start):
+    x = range(50)
+    class A(object):
+        def f1(self, a):
+            return False
+
+    x = range(50)
+    a = A()
+    f1 = a.f1
+    flt = filter
+
+    start()
+    i = 0
+    while i < N:
+        flt(f1, x)
+        i+=1
+
+run(w, 200)

Added: pypy/dist/pypy/interpreter/callbench/bmmore.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/bmmore.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,30 @@
+from sup import run
+
+def w(N, start):
+    class A(object):
+        def f4(self, a, b, c, d):
+            pass
+        def f5(self, a, b, c, d, e):
+            pass
+    a = A()
+    f4 = a.f4
+    f5 = a.f5
+
+    start()
+    i = 0
+    while i < N:
+        f4(1, 2, 3, 4)
+        f4(1, 2, 3, 4)
+        f4(1, 2, 3, 4)    
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f4(1, 2, 3, 4)
+        f4(1, 2, 3, 4)
+        f4(1, 2, 3, 4)    
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)        
+        i+=1
+    
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/compare.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/compare.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,22 @@
+# compare.py <results-file> <reference-results-file>
+
+import sys
+
+def main(cur, ref):
+    cur = open(cur, 'rU')
+    ref = open(ref, 'rU')
+    try:
+        while True:
+            cur_line = cur.next()
+            ref_line = ref.next()
+            cur_name, cur_t = cur_line.split()
+            ref_name, ref_t = ref_line.split()
+            assert cur_name == ref_name
+            cur_t = float(cur_t)
+            ref_t = float(ref_t)            
+            print "%-16s %.06g (x%.02f)" % (cur_name, cur_t, cur_t/ref_t)
+    except StopIteration:
+        pass
+
+if __name__ == '__main__':
+    main(sys.argv[1], sys.argv[2])

Added: pypy/dist/pypy/interpreter/callbench/f04.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/f04.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,39 @@
+from sup import run
+
+def w(N, start):
+    def f0():
+        pass
+    def f1(a):
+        pass
+    def f2(a, b):
+        pass
+    def f3(a, b, c):
+        pass
+    def f4(a, b, c, d):
+        pass
+    def f5(a, b, c, d, e):
+        pass
+
+    start()
+    i = 0
+    while i < N:
+        f0()
+        f0()
+        f0()
+        f1(1)
+        f1(1)
+        f2(1, 2)
+        f3(1, 2, 3)
+        f4(1, 2, 3, 4)
+        f5(1, 2, 3, 4, 5)
+        f0()
+        f0()
+        f0()
+        f1(1)
+        f1(1)
+        f2(1, 2)
+        f3(1, 2, 3)
+        f4(1, 2, 3, 4)        
+        i+=1
+
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/fabvararg.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/fabvararg.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,26 @@
+from sup import run
+
+def w(N, start):
+    def f(a, b, *args):
+        pass
+
+    z = (3, 4, 5)
+    start()
+
+    i = 0
+    while i < N:
+        f(1, 2, *z)
+        f(1, 2, *z)    
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)    
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)
+        f(1, 2, *z)        
+        i+=1
+
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/ffilter.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/ffilter.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,14 @@
+from sup import run
+
+def w(N, start):
+    def f1(a):
+        return False
+    x = range(50)
+
+    start()
+    i = 0
+    while i < N:
+        filter(f1, x)
+        i+=1
+    
+run(w, 200)

Added: pypy/dist/pypy/interpreter/callbench/ffunccall.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/ffunccall.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,36 @@
+from sup import run
+
+def w(N, start):
+    class A(object):
+        def foo(self, x):
+            pass
+
+        __add__ = foo
+
+    a = A()
+    a1 = A()
+
+    start()
+    i = 0
+    while i < N:
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        a + a1
+        i+=1
+    
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/fmore.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/fmore.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,28 @@
+from sup import run
+
+def w(N, start):
+    def f5(a, b, c, d, e):
+        pass
+    def f6(a, b, c, d, e, f):
+        pass
+
+    start()
+
+    i = 0
+    while i < N:
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+        f5(1, 2, 3, 4, 5)
+
+        f6(1, 2, 3, 4, 5, 6)
+        f6(1, 2, 3, 4, 5, 6)
+        f6(1, 2, 3, 4, 5, 6)
+        f6(1, 2, 3, 4, 5, 6)
+        f6(1, 2, 3, 4, 5, 6)
+        f6(1, 2, 3, 4, 5, 6)            
+        i+=1
+
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/inst.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/inst.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,22 @@
+from sup import run
+
+def w(N, start):
+    class A(object):
+        def __init__(self):
+            pass
+
+    start()
+    i = 0
+    while i < N:
+        A()
+        A()
+        A()
+        A()
+        A()
+        A()
+        A()
+        A()        
+        A()
+        i+=1
+    
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/instcall.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/instcall.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,35 @@
+from sup import run
+
+def w(N, start):
+    class A(object):
+        def __call__(self):
+            pass
+
+    a = A()
+
+    start()
+    i = 0
+    while i < N:
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()
+        a()        
+        a()
+        a()
+        i+=1
+    
+run(w, 1000)

Added: pypy/dist/pypy/interpreter/callbench/sup.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/interpreter/callbench/sup.py	Fri Aug  1 19:20:08 2008
@@ -0,0 +1,29 @@
+import sys, time
+
+def ref(N, start):
+    start()
+    i = 0
+    while i < N:
+        i+=1
+
+
+def run(func, n):
+    n *= int(sys.argv[1])
+    st = [None]
+    t = time.time
+
+    def start():
+        st[0] = t()
+
+    ref(n, start)
+    elapsed_ref = t() - st[0]
+
+    func(n, start)
+    elapsed = t() - st[0]
+
+    #if elapsed < elapsed_ref*10:
+    #    print "not enough meat", elapsed, elapsed_ref
+
+    print sys.argv[0].replace('.py', ''), elapsed-elapsed_ref
+    
+



More information about the Pypy-commit mailing list