Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r45624:40bfcf443937
Date: 2011-07-15 06:34 -0700
http://bitbucket.org/pypy/pypy/changeset/40bfcf443937/

Log:    start of new benchmarks

diff --git a/pypy/module/cppyy/bench/Makefile b/pypy/module/cppyy/bench/Makefile
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/bench/Makefile
@@ -0,0 +1,29 @@
+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
+else
+  genreflexflags=--with-methptrgetter
+  cppflags2=-Wno-pmf-conversions -O3
+endif
+
+
+bench02Dict_reflex.so: bench02.h bench02.xml
+       $(genreflex) bench02.h $(genreflexflags) --selection=bench02.xml 
-I$(ROOTSYS)/include
+       g++ -o $@ bench02.cxx bench02_rflx.cpp -I$(ROOTSYS)/include -shared 
-lReflex `root-config --libs` $(cppflags) $(cppflags2)
diff --git a/pypy/module/cppyy/bench/bench02.cxx 
b/pypy/module/cppyy/bench/bench02.cxx
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/bench/bench02.cxx
@@ -0,0 +1,20 @@
+#include "bench02.h"
+#include "TROOT.h"
+#include "TApplication.h"
+#include "TDirectory.h"
+
+#include <iostream>
+
+CloserHack::CloserHack() {
+   std::cout << "gROOT is: " << gROOT << std::endl;
+   std::cout << "gApplication is: " << gApplication << std::endl;
+}
+
+CloserHack::~CloserHack() {
+   std::cout << "closing file ... " << std::endl;
+   if (gDirectory && gDirectory != gROOT) {
+       gDirectory->Write();
+       gDirectory->Close();
+   }
+}
+
diff --git a/pypy/module/cppyy/bench/bench02.h 
b/pypy/module/cppyy/bench/bench02.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/bench/bench02.h
@@ -0,0 +1,23 @@
+#include "TCanvas.h"
+#include "TFile.h"
+#include "TProfile.h"
+#include "TNtuple.h"
+#include "TH1F.h"
+#include "TH2F.h"
+
+#include "TROOT.h"
+#include "TApplication.h"
+
+
+class CloserHack {
+public:
+   CloserHack();
+   ~CloserHack();
+};
+
+/*
+gROOT      = cppyy.gbl.gROOT
+gBenchmark = cppyy.gbl.gBenchmark
+gRandom    = cppyy.gbl.gRandom
+gSystem    = cppyy.gbl.gSystem
+*/
diff --git a/pypy/module/cppyy/bench/bench02.xml 
b/pypy/module/cppyy/bench/bench02.xml
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/bench/bench02.xml
@@ -0,0 +1,42 @@
+<lcgdict>
+
+  <!-- base classes -->
+  <class name="TROOT" />
+  <class name="TApplication" />
+
+  <class name="TObject" />
+  <class name="TNamed" />
+
+  <class name="TQObject" />
+  <class name="TAttPad" />
+  <class name="TAttFill" />
+  <class name="TAttLine" />
+  <class name="TAttMarker" />
+  <class name="TVirtualPad" />
+  <class name="TPad" />
+
+  <class name="TDirectory" />
+  <class name="TDirectoryFile" />
+
+  <class name="TH1" />
+  <class name="TH2" />
+  <class name="TH1D" />
+
+  <class name="TArray" />
+  <class name="TArrayD" />
+  <class name="TArrayF" />
+
+  <class name="TTree" /> -->
+
+  <!-- desired classes -->
+  <class name="TCanvas" />
+  <class name="TFile" />
+  <class name="TProfile" />
+  <class name="TNtuple" />
+  <class name="TH1F" />
+  <class name="TH2F" />
+
+  <!-- helper -->
+  <class name="CloserHack" />
+
+</lcgdict>
diff --git a/pypy/module/cppyy/bench/hsimple.C 
b/pypy/module/cppyy/bench/hsimple.C
new file mode 100755
--- /dev/null
+++ b/pypy/module/cppyy/bench/hsimple.C
@@ -0,0 +1,116 @@
+#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 <TRandom.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
+   gRandom->SetSeed();
+   Float_t px, py, pz;
+   const Int_t kUPDATE = 1000;
+   for (Int_t i = 0; i < 2500000; i++) {
+      gRandom->Rannor(px,py);
+      pz = px*px + py*py;
+ //     Float_t random = gRandom->Rndm(1);
+      hpx->Fill(px);
+/*
+      hpxpy->Fill(px,py);
+      hprof->Fill(px,pz);
+      ntuple->Fill(px,py,pz,random,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
new file mode 100755
--- /dev/null
+++ b/pypy/module/cppyy/bench/hsimple.py
@@ -0,0 +1,106 @@
+#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+#*-*
+#*-*  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 cppyy, random
+   cppyy.load_lib('bench02Dict_reflex.so')
+
+   TCanvas  = cppyy.gbl.TCanvas
+   TFile    = cppyy.gbl.TFile
+   TProfile = cppyy.gbl.TProfile
+   TNtuple  = cppyy.gbl.TNtuple
+   TH1F     = cppyy.gbl.TH1F
+   TH2F     = cppyy.gbl.TH2F
+except ImportError:
+   from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F
+   import random
+
+#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 )
+#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
+
+# 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)
+#   pt = (px*px + py*py)**0.5
+   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' )
+
+# Save all objects in this file.
+#hpx.SetFillColor( 0 )
+#hfile.Write()
+hfile.Close()
+#hpx.SetFillColor( 48 )
+#c1.Modified()
+#c1.Update()
+#import gc
+#gc.collect()
+  
+# Note that the file is automatically closed when application terminates
+# or when the file destructor is called.
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to