Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: cppyy-packaging Changeset: r92010:74ed34cfb42c Date: 2017-07-31 16:51 -0700 http://bitbucket.org/pypy/pypy/changeset/74ed34cfb42c/
Log: remove benchmarking code diff --git a/pypy/module/_cppyy/bench/Makefile b/pypy/module/_cppyy/bench/Makefile deleted file mode 100644 --- a/pypy/module/_cppyy/bench/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -all: bench02Dict_reflex.so - -ROOTSYS := ${ROOTSYS} - -ifeq ($(ROOTSYS),) - genreflex=genreflex - cppflags= -else - genreflex=$(ROOTSYS)/bin/genreflex - cppflags=-I$(ROOTSYS)/include -L$(ROOTSYS)/lib -endif - -PLATFORM := $(shell uname -s) -ifeq ($(PLATFORM),Darwin) - cppflags+=-dynamiclib -single_module -arch x86_64 -endif - -ifeq ($(shell $(genreflex) --help | grep -- --with-methptrgetter),) - genreflexflags= - cppflags2=-O3 -fPIC -else - genreflexflags=--with-methptrgetter - cppflags2=-Wno-pmf-conversions -O3 -fPIC -endif - - -bench02Dict_reflex.so: bench02.h bench02.cxx bench02.xml - $(genreflex) bench02.h $(genreflexflags) --selection=bench02.xml -I$(ROOTSYS)/include - g++ -o $@ bench02.cxx bench02_rflx.cpp -I$(ROOTSYS)/include -shared -std=c++11 -lHistPainter `root-config --libs` $(cppflags) $(cppflags2) diff --git a/pypy/module/_cppyy/bench/bench02.cxx b/pypy/module/_cppyy/bench/bench02.cxx deleted file mode 100644 --- a/pypy/module/_cppyy/bench/bench02.cxx +++ /dev/null @@ -1,79 +0,0 @@ -#include "bench02.h" - -#include "TROOT.h" -#include "TApplication.h" -#include "TDirectory.h" -#include "TInterpreter.h" -#include "TSystem.h" -#include "TBenchmark.h" -#include "TStyle.h" -#include "TError.h" -#include "Getline.h" -#include "TVirtualX.h" - -#include "Api.h" - -#include <iostream> - -TClass *TClass::GetClass(const char*, Bool_t, Bool_t) { - static TClass* dummy = new TClass("__dummy__", kTRUE); - return dummy; // is deleted by gROOT at shutdown -} - -class TTestApplication : public TApplication { -public: - TTestApplication( - const char* acn, Int_t* argc, char** argv, Bool_t bLoadLibs = kTRUE); - virtual ~TTestApplication(); -}; - -TTestApplication::TTestApplication( - const char* acn, int* argc, char** argv, bool do_load) : TApplication(acn, argc, argv) { - if (do_load) { - // follow TRint to minimize differences with CINT - ProcessLine("#include <iostream>", kTRUE); - ProcessLine("#include <_string>", kTRUE); // for std::string iostream. - ProcessLine("#include <vector>", kTRUE); // needed because they're used within the - ProcessLine("#include <pair>", kTRUE); // core ROOT dicts and CINT won't be able - // to properly unload these files - } - - // save current interpreter context - gInterpreter->SaveContext(); - gInterpreter->SaveGlobalsContext(); - - // prevent crashes on accessing history - Gl_histinit((char*)"-"); - - // prevent ROOT from exiting python - SetReturnFromRun(kTRUE); -} - -TTestApplication::~TTestApplication() {} - -static const char* appname = "pypy-cppyy"; - -Bench02RootApp::Bench02RootApp() { - gROOT->SetBatch(kTRUE); - if (!gApplication) { - int argc = 1; - char* argv[1]; argv[0] = (char*)appname; - gApplication = new TTestApplication(appname, &argc, argv, kFALSE); - } -} - -Bench02RootApp::~Bench02RootApp() { - // TODO: ROOT globals cleanup ... (?) -} - -void Bench02RootApp::report() { - std::cout << "gROOT is: " << gROOT << std::endl; - std::cout << "gApplication is: " << gApplication << std::endl; -} - -void Bench02RootApp::close_file(TFile* f) { - std::cout << "closing file " << f->GetName() << " ... " << std::endl; - f->Write(); - f->Close(); - std::cout << "... file closed" << std::endl; -} diff --git a/pypy/module/_cppyy/bench/bench02.h b/pypy/module/_cppyy/bench/bench02.h deleted file mode 100644 --- a/pypy/module/_cppyy/bench/bench02.h +++ /dev/null @@ -1,72 +0,0 @@ -#include "TString.h" - -#include "TCanvas.h" -#include "TFile.h" -#include "TProfile.h" -#include "TNtuple.h" -#include "TH1F.h" -#include "TH2F.h" -#include "TRandom.h" -#include "TRandom3.h" - -#include "TROOT.h" -#include "TApplication.h" -#include "TSystem.h" - -#include "TArchiveFile.h" -#include "TBasket.h" -#include "TBenchmark.h" -#include "TBox.h" -#include "TBranchRef.h" -#include "TBrowser.h" -#include "TClassGenerator.h" -#include "TClassRef.h" -#include "TClassStreamer.h" -#include "TContextMenu.h" -#include "TEntryList.h" -#include "TEventList.h" -#include "TF1.h" -#include "TFileCacheRead.h" -#include "TFileCacheWrite.h" -#include "TFileMergeInfo.h" -#include "TFitResult.h" -#include "TFolder.h" -//#include "TFormulaPrimitive.h" -#include "TFunction.h" -#include "TFrame.h" -#include "TGlobal.h" -#include "THashList.h" -#include "TInetAddress.h" -#include "TInterpreter.h" -#include "TKey.h" -#include "TLegend.h" -#include "TMethodCall.h" -#include "TPluginManager.h" -#include "TProcessUUID.h" -#include "TSchemaRuleSet.h" -#include "TStyle.h" -#include "TSysEvtHandler.h" -#include "TTimer.h" -#include "TView.h" -//#include "TVirtualCollectionProxy.h" -#include "TVirtualFFT.h" -#include "TVirtualHistPainter.h" -#include "TVirtualIndex.h" -#include "TVirtualIsAProxy.h" -#include "TVirtualPadPainter.h" -#include "TVirtualRefProxy.h" -#include "TVirtualStreamerInfo.h" -#include "TVirtualViewer3D.h" - -#include <typeinfo> -#include <ostream> - - -class Bench02RootApp { -public: - Bench02RootApp(); - ~Bench02RootApp(); - - void report(); - void close_file(TFile* f); -}; diff --git a/pypy/module/_cppyy/bench/bench02.xml b/pypy/module/_cppyy/bench/bench02.xml deleted file mode 100644 --- a/pypy/module/_cppyy/bench/bench02.xml +++ /dev/null @@ -1,41 +0,0 @@ -<lcgdict> - - <selection> - - <!-- ROOT classes --> - <class pattern="T[A-Z]*" /> - <class pattern="ROOT::T[A-Z]*" /> - <class pattern="ROOT::Fit::*" /> - - <!-- ROOT globals --> - <variable name="gROOT" /> - <variable name="gSystem" /> - <variable name="gRandom" /> - - <!-- STL classes actually used --> - <class name="std::string" /> - <class name="std::ostream" /> - <class name="std::type_info" /> - <class pattern="std::vector<*>" /> - <class pattern="std::_Vector_base<*>" /> - - <!-- helper --> - <class name="Bench02RootApp" /> - - </selection> - - <exclusion> - - <struct pattern="TString::*" /> - <class name="TString" > - <field name="fRep" transient="true"/> - </class> - - <class name="TUUID::uuid_time_t" /> - - <class name="TClass::TNameMapNode" /> - <class name="TFileOpenHandle" /> - - </exclusion> - -</lcgdict> diff --git a/pypy/module/_cppyy/bench/hsimple.C b/pypy/module/_cppyy/bench/hsimple.C deleted file mode 100644 --- a/pypy/module/_cppyy/bench/hsimple.C +++ /dev/null @@ -1,109 +0,0 @@ -#include <TFile.h> -#include <TNtuple.h> -#include <TH2.h> -#include <TProfile.h> -#include <TCanvas.h> -#include <TFrame.h> -#include <TROOT.h> -#include <TSystem.h> -#include <TRandom3.h> -#include <TBenchmark.h> -#include <TInterpreter.h> - -TFile *hsimple(Int_t get=0) -{ -// This program creates : -// - a one dimensional histogram -// - a two dimensional histogram -// - a profile histogram -// - a memory-resident ntuple -// -// These objects are filled with some random numbers and saved on a file. -// If get=1 the macro returns a pointer to the TFile of "hsimple.root" -// if this file exists, otherwise it is created. -// The file "hsimple.root" is created in $ROOTSYS/tutorials if the caller has -// write access to this directory, otherwise the file is created in $PWD - - TString filename = "hsimple.root"; - TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName()); - dir.ReplaceAll("hsimple.C",""); - dir.ReplaceAll("/./","/"); - TFile *hfile = 0; - if (get) { - // if the argument get =1 return the file "hsimple.root" - // if the file does not exist, it is created - TString fullPath = dir+"hsimple.root"; - if (!gSystem->AccessPathName(fullPath,kFileExists)) { - hfile = TFile::Open(fullPath); //in $ROOTSYS/tutorials - if (hfile) return hfile; - } - //otherwise try $PWD/hsimple.root - if (!gSystem->AccessPathName("hsimple.root",kFileExists)) { - hfile = TFile::Open("hsimple.root"); //in current dir - if (hfile) return hfile; - } - } - //no hsimple.root file found. Must generate it ! - //generate hsimple.root in $ROOTSYS/tutorials if we have write access - if (!gSystem->AccessPathName(dir,kWritePermission)) { - filename = dir+"hsimple.root"; - } else if (!gSystem->AccessPathName(".",kWritePermission)) { - //otherwise generate hsimple.root in the current directory - } else { - printf("you must run the script in a directory with write access\n"); - return 0; - } - hfile = (TFile*)gROOT->FindObject(filename); if (hfile) hfile->Close(); - hfile = new TFile(filename,"RECREATE","Demo ROOT file with histograms"); - - // Create some histograms, a profile histogram and an ntuple - TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4); - hpx->SetFillColor(48); - TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4); - TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20); - TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i"); - - gBenchmark->Start("hsimple"); - - // Create a new canvas. - TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500); - c1->SetFillColor(42); - c1->GetFrame()->SetFillColor(21); - c1->GetFrame()->SetBorderSize(6); - c1->GetFrame()->SetBorderMode(-1); - - - // Fill histograms randomly - TRandom3 random; - Float_t px, py, pz; - const Int_t kUPDATE = 1000; - for (Int_t i = 0; i < 50000; i++) { - // random.Rannor(px,py); - px = random.Gaus(0, 1); - py = random.Gaus(0, 1); - pz = px*px + py*py; - Float_t rnd = random.Rndm(1); - hpx->Fill(px); - hpxpy->Fill(px,py); - hprof->Fill(px,pz); - ntuple->Fill(px,py,pz,rnd,i); - if (i && (i%kUPDATE) == 0) { - if (i == kUPDATE) hpx->Draw(); - c1->Modified(); - c1->Update(); - if (gSystem->ProcessEvents()) - break; - } - } - gBenchmark->Show("hsimple"); - - // Save all objects in this file - hpx->SetFillColor(0); - hfile->Write(); - hpx->SetFillColor(48); - c1->Modified(); - return hfile; - -// Note that the file is automatically close when application terminates -// or when the file destructor is called. -} diff --git a/pypy/module/_cppyy/bench/hsimple.py b/pypy/module/_cppyy/bench/hsimple.py deleted file mode 100755 --- a/pypy/module/_cppyy/bench/hsimple.py +++ /dev/null @@ -1,110 +0,0 @@ -#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -#*-* -#*-* This program creates : -#*-* - a one dimensional histogram -#*-* - a two dimensional histogram -#*-* - a profile histogram -#*-* - a memory-resident ntuple -#*-* -#*-* These objects are filled with some random numbers and saved on a file. -#*-* -#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* - -_reflex = True # to keep things equal, set to False for full macro - -try: - import cppyy, random - - if not hasattr(cppyy.gbl, 'gROOT'): - cppyy.load_reflection_info('bench02Dict_reflex.so') - _reflex = True - - TCanvas = cppyy.gbl.TCanvas - TFile = cppyy.gbl.TFile - TProfile = cppyy.gbl.TProfile - TNtuple = cppyy.gbl.TNtuple - TH1F = cppyy.gbl.TH1F - TH2F = cppyy.gbl.TH2F - TRandom3 = cppyy.gbl.TRandom3 - - gROOT = cppyy.gbl.gROOT - gBenchmark = cppyy.gbl.TBenchmark() - gSystem = cppyy.gbl.gSystem - -except ImportError: - from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F, TRandom3 - from ROOT import gROOT, gBenchmark, gSystem - import random - -if _reflex: - gROOT.SetBatch(True) - -# Create a new ROOT binary machine independent file. -# Note that this file may contain any kind of ROOT objects, histograms, -# pictures, graphics objects, detector geometries, tracks, events, etc.. -# This file is now becoming the current directory. - -if not _reflex: - hfile = gROOT.FindObject('hsimple.root') - if hfile: - hfile.Close() - hfile = TFile('hsimple.root', 'RECREATE', 'Demo ROOT file with histograms' ) - -# Create some histograms, a profile histogram and an ntuple -hpx = TH1F('hpx', 'This is the px distribution', 100, -4, 4) -hpx.SetFillColor(48) -hpxpy = TH2F('hpxpy', 'py vs px', 40, -4, 4, 40, -4, 4) -hprof = TProfile('hprof', 'Profile of pz versus px', 100, -4, 4, 0, 20) -if not _reflex: - ntuple = TNtuple('ntuple', 'Demo ntuple', 'px:py:pz:random:i') - -gBenchmark.Start('hsimple') - -# Create a new canvas, and customize it. -c1 = TCanvas('c1', 'Dynamic Filling Example', 200, 10, 700, 500) -c1.SetFillColor(42) -c1.GetFrame().SetFillColor(21) -c1.GetFrame().SetBorderSize(6) -c1.GetFrame().SetBorderMode(-1) - -# Fill histograms randomly. -random = TRandom3() -kUPDATE = 1000 -for i in xrange(50000): - # Generate random numbers -# px, py = random.gauss(0, 1), random.gauss(0, 1) - px, py = random.Gaus(0, 1), random.Gaus(0, 1) - pz = px*px + py*py -# rnd = random.random() - rnd = random.Rndm(1) - - # Fill histograms - hpx.Fill(px) - hpxpy.Fill(px, py) - hprof.Fill(px, pz) - if not _reflex: - ntuple.Fill(px, py, pz, rnd, i) - - # Update display every kUPDATE events - if i and i%kUPDATE == 0: - if i == kUPDATE: - hpx.Draw() - - c1.Modified(True) - c1.Update() - - if gSystem.ProcessEvents(): # allow user interrupt - break - -gBenchmark.Show( 'hsimple' ) - -# Save all objects in this file -hpx.SetFillColor(0) -if not _reflex: - hfile.Write() -hpx.SetFillColor(48) -c1.Modified(True) -c1.Update() - -# Note that the file is automatically closed when application terminates -# or when the file destructor is called. diff --git a/pypy/module/_cppyy/bench/hsimple_rflx.py b/pypy/module/_cppyy/bench/hsimple_rflx.py deleted file mode 100755 --- a/pypy/module/_cppyy/bench/hsimple_rflx.py +++ /dev/null @@ -1,120 +0,0 @@ -#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -#*-* -#*-* This program creates : -#*-* - a one dimensional histogram -#*-* - a two dimensional histogram -#*-* - a profile histogram -#*-* - a memory-resident ntuple -#*-* -#*-* These objects are filled with some random numbers and saved on a file. -#*-* -#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* - -try: - import warnings - warnings.simplefilter("ignore") - - import cppyy, random - cppyy.load_reflection_info('bench02Dict_reflex.so') - - app = cppyy.gbl.Bench02RootApp() - TCanvas = cppyy.gbl.TCanvas - TFile = cppyy.gbl.TFile - TProfile = cppyy.gbl.TProfile - TNtuple = cppyy.gbl.TNtuple - TH1F = cppyy.gbl.TH1F - TH2F = cppyy.gbl.TH2F - TRandom = cppyy.gbl.TRandom -except ImportError: - from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F, TRandom - import random - -import math - -#gROOT = cppyy.gbl.gROOT -#gBenchmark = cppyy.gbl.gBenchmark -#gRandom = cppyy.gbl.gRandom -#gSystem = cppyy.gbl.gSystem - -#gROOT.Reset() - -# Create a new canvas, and customize it. -#c1 = TCanvas( 'c1', 'Dynamic Filling Example', 200, 10, 700, 500 ) -#c1.SetFillColor( 42 ) -#c1.GetFrame().SetFillColor( 21 ) -#c1.GetFrame().SetBorderSize( 6 ) -#c1.GetFrame().SetBorderMode( -1 ) - -# Create a new ROOT binary machine independent file. -# Note that this file may contain any kind of ROOT objects, histograms, -# pictures, graphics objects, detector geometries, tracks, events, etc.. -# This file is now becoming the current directory. - -#hfile = gROOT.FindObject( 'hsimple.root' ) -#if hfile: -# hfile.Close() -#hfile = TFile( 'hsimple.root', 'RECREATE', 'Demo ROOT file with histograms' ) - -# Create some histograms, a profile histogram and an ntuple -hpx = TH1F('hpx', 'This is the px distribution', 100, -4, 4) -hpx.Print() -#hpxpy = TH2F( 'hpxpy', 'py vs px', 40, -4, 4, 40, -4, 4 ) -#hprof = TProfile( 'hprof', 'Profile of pz versus px', 100, -4, 4, 0, 20 ) -#ntuple = TNtuple( 'ntuple', 'Demo ntuple', 'px:py:pz:random:i' ) - -# Set canvas/frame attributes. -#hpx.SetFillColor( 48 ) - -#gBenchmark.Start( 'hsimple' ) - -# Initialize random number generator. -#gRandom.SetSeed() -#rannor, rndm = gRandom.Rannor, gRandom.Rndm - -random = TRandom() -random.SetSeed(0) - -# Fill histograms randomly. -#px, py = Double(), Double() -kUPDATE = 1000 -for i in xrange(2500000): - # Generate random values. -# px, py = random.gauss(0, 1), random.gauss(0, 1) - px, py = random.Gaus(0, 1), random.Gaus(0, 1) -# pt = (px*px + py*py)**0.5 - pt = math.sqrt(px*px + py*py) -# pt = (px*px + py*py) -# random = rndm(1) - - # Fill histograms. - hpx.Fill(pt) -# hpxpyFill( px, py ) -# hprofFill( px, pz ) -# ntupleFill( px, py, pz, random, i ) - - # Update display every kUPDATE events. -# if i and i%kUPDATE == 0: -# if i == kUPDATE: -# hpx.Draw() - -# c1.Modified() -# c1.Update() - -# if gSystem.ProcessEvents(): # allow user interrupt -# break - -#gBenchmark.Show( 'hsimple' ) - -hpx.Print() - -# Save all objects in this file. -#hpx.SetFillColor( 0 ) -#hfile.Write() -#hfile.Close() -#hpx.SetFillColor( 48 ) -#c1.Modified() -#c1.Update() -#c1.Draw() - -# Note that the file is automatically closed when application terminates -# or when the file destructor is called. diff --git a/pypy/module/_cppyy/test/bench1.cxx b/pypy/module/_cppyy/test/bench1.cxx deleted file mode 100644 --- a/pypy/module/_cppyy/test/bench1.cxx +++ /dev/null @@ -1,39 +0,0 @@ -#include <iostream> -#include <iomanip> -#include <time.h> -#include <unistd.h> - -#include "example01.h" - -static const int NNN = 10000000; - - -int cpp_loop_offset() { - int i = 0; - for ( ; i < NNN*10; ++i) - ; - return i; -} - -int cpp_bench1() { - int i = 0; - example01 e; - for ( ; i < NNN*10; ++i) - e.addDataToInt(i); - return i; -} - - -int main() { - - clock_t t1 = clock(); - cpp_loop_offset(); - clock_t t2 = clock(); - cpp_bench1(); - clock_t t3 = clock(); - - std::cout << std::setprecision(8) - << ((t3-t2) - (t2-t1))/((double)CLOCKS_PER_SEC*10.) << std::endl; - - return 0; -} diff --git a/pypy/module/_cppyy/test/bench1.py b/pypy/module/_cppyy/test/bench1.py deleted file mode 100644 --- a/pypy/module/_cppyy/test/bench1.py +++ /dev/null @@ -1,244 +0,0 @@ -import commands, os, sys, time, math - -from math import atan -NNN = 10000000 - - -def run_bench(bench): - global t_loop_offset, NNN - - t1 = time.time() - bench(NNN) - t2 = time.time() - - t_bench = (t2-t1) - return bench.scale*t_bench-t_loop_offset - -def print_bench(name, t_bench): - global t_cppref - print ':::: %s cost: %#6.3fs (%#4.1fx)' % (name, t_bench, float(t_bench)/t_cppref) - -def python_loop_offset(): - for i in xrange(NNN): - i - return i - -class CPythonBench1(object): - scale = 1 - def __init__(self): - import ROOT - ROOT.gROOT.SetBatch(1) - ROOT.SetSignalPolicy(ROOT.kSignalFast) - import cppyy - self.lib = cppyy.gbl.gSystem.Load("./example01Dict.so") - - self.cls = cppyy.gbl.example01 - self.inst = self.cls(0) - - def __call__(self, repeat): - # TODO: check linearity of actual scaling - instance = self.inst - niter = repeat/self.scale - self.cls.addDataToInt._threaded = True - for i in xrange(niter): - instance.addDataToInt(i) - return i - -class CPythonBench1_Swig(object): - scale = 1 - def __init__(self): - import example - - 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 - def __init__(self): - import cppyy - self.lib = cppyy.load_reflection_info("./example01Dict.so") - - self.cls = cppyy._scope_byname("example01") - self.inst = self.cls.get_overload(self.cls.type_name).call(None, 0) - - def __call__(self, repeat): - addDataToInt = self.cls.get_overload("addDataToInt") - instance = self.inst - for i in xrange(repeat): - addDataToInt.call(instance, i) - return i - -class CppyyInterpBench2(CppyyInterpBench1): - title = "... overload" - def __call__(self, repeat): - addDataToInt = self.cls.get_overload("overloadedAddDataToInt") - instance = self.inst - for i in xrange(repeat): - addDataToInt.call(instance, i) - return i - -class CppyyInterpBench3(CppyyInterpBench1): - title = "... constref" - def __call__(self, repeat): - addDataToInt = self.cls.get_overload("addDataToIntConstRef") - instance = self.inst - for i in xrange(repeat): - addDataToInt.call(instance, i) - return i - -class CppyyPythonBench1(object): - title = "cppyy python" - scale = 1 - def __init__(self): - import cppyy - self.lib = cppyy.load_reflection_info("./example01Dict.so") - - self.cls = cppyy.gbl.example01 - self.inst = self.cls(0) - - def __call__(self, repeat): - instance = self.inst - for i in xrange(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 xrange(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 xrange(repeat): - instance.cyclePayload(pl) - return i - - -if __name__ == '__main__': - python_loop_offset(); - - # time python loop offset - t1 = time.time() - python_loop_offset() - t2 = time.time() - t_loop_offset = t2-t1 - - # 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) - 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 ... " - # 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) - - # create object - benches = [ - CppyyInterpBench1(), CppyyInterpBench2(), CppyyInterpBench3(), - CppyyPythonBench1(), CppyyPythonBench2(), CppyyPythonBench3() ] - - # warm-up - print "warming up ... " - for bench in benches: - bench(2000) - - # to allow some consistency checking - print "C++ reference uses %.3fs" % t_cppref - - # test runs ... - for bench in benches: - print_bench(bench.title, run_bench(bench)) - - 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)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit