[pypy-commit] pypy cling-support: more detailed benchmarks, used for paper
wlav
pypy.commits at gmail.com
Tue Sep 13 14:14:25 EDT 2016
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: cling-support
Changeset: r87094:0477318b132d
Date: 2016-09-13 09:27 -0700
http://bitbucket.org/pypy/pypy/changeset/0477318b132d/
Log: more detailed benchmarks, used for paper
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
@@ -1,5 +1,6 @@
-import commands, os, sys, time
+import commands, os, sys, time, math
+from math import atan
NNN = 10000000
@@ -18,36 +19,69 @@
print ':::: %s cost: %#6.3fs (%#4.1fx)' % (name, t_bench, float(t_bench)/t_cppref)
def python_loop_offset():
- for i in range(NNN):
+ for i in xrange(NNN):
i
return i
-class PyCintexBench1(object):
- scale = 5
+class CPythonBench1(object):
+ scale = 1
def __init__(self):
- import PyCintex
- self.lib = PyCintex.gbl.gSystem.Load("./example01Dict.so")
+ import ROOT
+ ROOT.gROOT.SetBatch(1)
+ ROOT.SetSignalPolicy(ROOT.kSignalFast)
+ import cppyy
+ self.lib = cppyy.gbl.gSystem.Load("./example01Dict.so")
- self.cls = PyCintex.gbl.example01
+ self.cls = cppyy.gbl.example01
self.inst = self.cls(0)
def __call__(self, repeat):
- # note that PyCintex calls don't actually scale linearly, but worse
- # than linear (leak or wrong filling of a cache??)
+ # TODO: check linearity of actual scaling
instance = self.inst
niter = repeat/self.scale
- for i in range(niter):
+ self.cls.addDataToInt._threaded = True
+ for i in xrange(niter):
instance.addDataToInt(i)
return i
-class PyROOTBench1(PyCintexBench1):
+class CPythonBench1_Swig(object):
+ scale = 1
def __init__(self):
- import ROOT
- self.lib = ROOT.gSystem.Load("./example01Dict.so")
+ import example
- self.cls = ROOT.example01
+ self.cls = example.example01
self.inst = self.cls(0)
+ def __call__(self, repeat):
+ # TODO: check linearity of actual scaling
+ instance = self.inst
+ niter = repeat/self.scale
+ for i in xrange(niter):
+ instance.addDataToInt(i)
+ return i
+
+
+class PureBench1(object):
+ scale = 1
+ def __init__(self):
+ class example01(object):
+ def __init__(self, somedata):
+ self.m_somedata = somedata
+ def addDataToInt(self, a):
+ return self.m_somedata + int(atan(a))
+
+ self.cls = example01
+ self.inst = self.cls(0)
+
+ def __call__(self, repeat):
+ # TODO: check linearity of actual scaling
+ instance = self.inst
+ niter = repeat/self.scale
+ for i in xrange(niter):
+ instance.addDataToInt(i)
+ return i
+
+
class CppyyInterpBench1(object):
title = "cppyy interp"
scale = 1
@@ -61,7 +95,7 @@
def __call__(self, repeat):
addDataToInt = self.cls.get_overload("addDataToInt")
instance = self.inst
- for i in range(repeat):
+ for i in xrange(repeat):
addDataToInt.call(instance, i)
return i
@@ -70,7 +104,7 @@
def __call__(self, repeat):
addDataToInt = self.cls.get_overload("overloadedAddDataToInt")
instance = self.inst
- for i in range(repeat):
+ for i in xrange(repeat):
addDataToInt.call(instance, i)
return i
@@ -79,7 +113,7 @@
def __call__(self, repeat):
addDataToInt = self.cls.get_overload("addDataToIntConstRef")
instance = self.inst
- for i in range(repeat):
+ for i in xrange(repeat):
addDataToInt.call(instance, i)
return i
@@ -95,7 +129,7 @@
def __call__(self, repeat):
instance = self.inst
- for i in range(repeat):
+ for i in xrange(repeat):
instance.addDataToInt(i)
return i
@@ -106,7 +140,7 @@
pl = cppyy.gbl.payload(3.14)
instance = self.inst
- for i in range(repeat):
+ for i in xrange(repeat):
instance.copyCyclePayload(pl)
return i
@@ -117,7 +151,7 @@
pl = cppyy.gbl.payload(3.14)
instance = self.inst
- for i in range(repeat):
+ for i in xrange(repeat):
instance.cyclePayload(pl)
return i
@@ -131,27 +165,36 @@
t2 = time.time()
t_loop_offset = t2-t1
- # special case for PyCintex (run under python, not pypy-c)
- if '--pycintex' in sys.argv:
- cintex_bench1 = PyCintexBench1()
- print run_bench(cintex_bench1)
+ # special cases for CPython
+ if '-swig' in sys.argv:
+ # runs SWIG
+ cpython_bench1 = CPythonBench1_Swig()
+ elif '-pure' in sys.argv:
+ # runs pure python
+ cpython_bench1 = PureBench1()
+ elif not 'cppyy' in sys.builtin_module_names:
+ # runs ROOT/cppyy.py
+ cpython_bench1 = CPythonBench1()
+ try:
+ print run_bench(cpython_bench1)
sys.exit(0)
-
- # special case for PyROOT (run under python, not pypy-c)
- if '--pyroot' in sys.argv:
- pyroot_bench1 = PyROOTBench1()
- print run_bench(pyroot_bench1)
- sys.exit(0)
+ except NameError:
+ pass
# get C++ reference point
if not os.path.exists("bench1.exe") or\
os.stat("bench1.exe").st_mtime < os.stat("bench1.cxx").st_mtime:
print "rebuilding bench1.exe ... "
- os.system( "g++ -O2 bench1.cxx example01.cxx -o bench1.exe" )
+ # the following is debatable, as pypy-c uses direct function
+ # pointers, whereas that is only true for virtual functions in
+ # the case of C++ (by default, anyway, it need not)
+ # yes, shared library use is what's going on ...
+# os.system( "g++ -O2 bench1.cxx example01.cxx -o bench1.exe" )
+ os.system( "g++ -O2 bench1.cxx -L. -lexample01Dict -o bench1.exe" )
stat, cppref = commands.getstatusoutput("./bench1.exe")
t_cppref = float(cppref)
- # created object
+ # create object
benches = [
CppyyInterpBench1(), CppyyInterpBench2(), CppyyInterpBench3(),
CppyyPythonBench1(), CppyyPythonBench2(), CppyyPythonBench3() ]
@@ -167,7 +210,35 @@
# test runs ...
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")
- #print_bench("pyroot ", float(t_pyroot))
+
+ stat, t_cpython1 = commands.getstatusoutput("/home/wlav/aditi/pypy/bin/v5/pypy-c bench1.py - -pure")
+ if stat:
+ print 'CPython pure bench1 failed:'
+ os.write(sys.stdout.fileno(), t_cpython1)
+ print
+ exit(stat)
+ print_bench("pypy-c pure ", float(t_cpython1))
+
+ stat, t_cpython1 = commands.getstatusoutput("python bench1.py - -pure")
+ if stat:
+ print 'CPython pure bench1 failed:'
+ os.write(sys.stdout.fileno(), t_cpython1)
+ print
+ exit(stat)
+ print_bench("CPython pure", float(t_cpython1))
+
+ stat, t_cpython1 = commands.getstatusoutput("python bench1.py - -b")
+ if stat:
+ print 'CPython bench1 failed:'
+ os.write(sys.stdout.fileno(), t_cpython1)
+ print
+ exit(stat)
+ print_bench("CPython ", float(t_cpython1))
+
+ #stat, t_cpython1 = commands.getstatusoutput("python bench1.py - -swig")
+ #if stat:
+ # print 'SWIG bench1 failed:'
+ # os.write(sys.stdout.fileno(), t_cpython1)
+ # print
+ # exit(stat)
+ #print_bench("SWIG ", float(t_cpython1))
More information about the pypy-commit
mailing list