[pypy-commit] pypy reflex-support: improve simple benchmarking (and shows problem with new objects)

wlav noreply at buildbot.pypy.org
Sat Jan 5 19:33:08 CET 2013


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r59755:b8153a9f359c
Date: 2012-12-19 09:45 -0800
http://bitbucket.org/pypy/pypy/changeset/b8153a9f359c/

Log:	improve simple benchmarking (and shows problem with new objects)

diff --git a/pypy/module/cppyy/test/bench1.py b/pypy/module/cppyy/test/bench1.py
--- a/pypy/module/cppyy/test/bench1.py
+++ b/pypy/module/cppyy/test/bench1.py
@@ -4,14 +4,14 @@
 
 
 def run_bench(bench):
-    global t_loop_offset
+    global t_loop_offset, NNN
 
     t1 = time.time()
-    bench()
+    bench(NNN)
     t2 = time.time()
 
-    t_bench = (t2-t1)-t_loop_offset
-    return bench.scale*t_bench
+    t_bench = (t2-t1)
+    return bench.scale*t_bench-t_loop_offset
 
 def print_bench(name, t_bench):
     global t_cppref
@@ -23,7 +23,7 @@
     return i
 
 class PyCintexBench1(object):
-    scale = 10
+    scale = 5
     def __init__(self):
         import PyCintex
         self.lib = PyCintex.gbl.gSystem.Load("./example01Dict.so")
@@ -31,11 +31,11 @@
         self.cls   = PyCintex.gbl.example01
         self.inst  = self.cls(0)
 
-    def __call__(self):
+    def __call__(self, repeat):
         # note that PyCintex calls don't actually scale linearly, but worse
         # than linear (leak or wrong filling of a cache??)
         instance = self.inst
-        niter = NNN/self.scale
+        niter = repeat/self.scale
         for i in range(niter):
             instance.addDataToInt(i)
         return i
@@ -43,12 +43,13 @@
 class PyROOTBench1(PyCintexBench1):
     def __init__(self):
         import ROOT
-        self.lib = ROOT.gSystem.Load("./example01Dict_cint.so")
+        self.lib = ROOT.gSystem.Load("./example01Dict.so")
 
         self.cls   = ROOT.example01
         self.inst  = self.cls(0)
 
 class CppyyInterpBench1(object):
+    title = "cppyy interp"
     scale = 1
     def __init__(self):
         import cppyy
@@ -57,30 +58,33 @@
         self.cls  = cppyy._scope_byname("example01")
         self.inst = self.cls.get_overload(self.cls.type_name).call(None, 0)
 
-    def __call__(self):
+    def __call__(self, repeat):
         addDataToInt = self.cls.get_overload("addDataToInt")
         instance = self.inst
-        for i in range(NNN):
+        for i in range(repeat):
             addDataToInt.call(instance, i)
         return i
 
 class CppyyInterpBench2(CppyyInterpBench1):
-    def __call__(self):
+    title = "... overload"
+    def __call__(self, repeat):
         addDataToInt = self.cls.get_overload("overloadedAddDataToInt")
         instance = self.inst
-        for i in range(NNN):
+        for i in range(repeat):
             addDataToInt.call(instance, i)
         return i
 
 class CppyyInterpBench3(CppyyInterpBench1):
-    def __call__(self):
+    title = "... constref"
+    def __call__(self, repeat):
         addDataToInt = self.cls.get_overload("addDataToIntConstRef")
         instance = self.inst
-        for i in range(NNN):
+        for i in range(repeat):
             addDataToInt.call(instance, i)
         return i
 
 class CppyyPythonBench1(object):
+    title = "cppyy python"
     scale = 1
     def __init__(self):
         import cppyy
@@ -89,12 +93,34 @@
         self.cls = cppyy.gbl.example01
         self.inst = self.cls(0)
 
-    def __call__(self):
+    def __call__(self, repeat):
         instance = self.inst
-        for i in range(NNN):
+        for i in range(repeat):
             instance.addDataToInt(i)
         return i
 
+class CppyyPythonBench2(CppyyPythonBench1):
+    title = "... objbyval"
+    def __call__(self, repeat):
+        import cppyy
+        pl = cppyy.gbl.payload(3.14)
+
+        instance = self.inst
+        for i in range(repeat):
+            instance.copyCyclePayload(pl)
+        return i
+
+class CppyyPythonBench3(CppyyPythonBench1):
+    title = "... objbyptr"
+    def __call__(self, repeat):
+        import cppyy
+        pl = cppyy.gbl.payload(3.14)
+
+        instance = self.inst
+        for i in range(repeat):
+            instance.cyclePayload(pl)
+        return i
+
 
 if __name__ == '__main__':
     python_loop_offset();
@@ -111,7 +137,7 @@
         print run_bench(cintex_bench1)
         sys.exit(0)
 
-    # special case for PyCintex (run under python, not pypy-c)
+    # special case for PyROOT (run under python, not pypy-c)
     if '--pyroot' in sys.argv:
         pyroot_bench1 = PyROOTBench1()
         print run_bench(pyroot_bench1)
@@ -125,22 +151,22 @@
     stat, cppref = commands.getstatusoutput("./bench1.exe")
     t_cppref = float(cppref)
 
+    # created object
+    benches = [
+        CppyyInterpBench1(), CppyyInterpBench2(), CppyyInterpBench3(),
+        CppyyPythonBench1(), CppyyPythonBench2(), CppyyPythonBench3() ]
+
     # warm-up
     print "warming up ... "
-    interp_bench1 = CppyyInterpBench1()
-    interp_bench2 = CppyyInterpBench2()
-    interp_bench3 = CppyyInterpBench3()
-    python_bench1 = CppyyPythonBench1()
-    interp_bench1(); interp_bench2(); python_bench1()
+    for bench in benches:
+        bench(2000)
 
     # to allow some consistency checking
     print "C++ reference uses %.3fs" % t_cppref
 
     # test runs ...
-    print_bench("cppyy interp", run_bench(interp_bench1))
-    print_bench("... overload", run_bench(interp_bench2))
-    print_bench("... constref", run_bench(interp_bench3))
-    print_bench("cppyy python", run_bench(python_bench1))
+    for bench in benches:
+        print_bench(bench.title, run_bench(bench))
     stat, t_cintex = commands.getstatusoutput("python bench1.py --pycintex")
     print_bench("pycintex    ", float(t_cintex))
     #stat, t_pyroot = commands.getstatusoutput("python bench1.py --pyroot")


More information about the pypy-commit mailing list