[pypy-commit] pypy reflex-support: hsimple benchmark improvements

wlav noreply at buildbot.pypy.org
Fri Aug 5 02:42:03 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r46282:3a02f1e69310
Date: 2011-08-04 10:55 -0700
http://bitbucket.org/pypy/pypy/changeset/3a02f1e69310/

Log:	hsimple benchmark improvements

diff --git a/pypy/module/cppyy/bench/bench02.cxx b/pypy/module/cppyy/bench/bench02.cxx
--- a/pypy/module/cppyy/bench/bench02.cxx
+++ b/pypy/module/cppyy/bench/bench02.cxx
@@ -16,8 +16,8 @@
 #include <iostream>
 
 TClass *TClass::GetClass(const char*, Bool_t, Bool_t) {
-   static TClass dummy("dummy");
-   return &dummy;
+    static TClass* dummy = new TClass("__dummy__", kTRUE);
+    return dummy;  // is deleted by gROOT at shutdown
 }
 
 class TTestApplication : public TApplication {
@@ -54,6 +54,7 @@
 static const char* appname = "pypy-cppyy";
 
 Bench02RootApp::Bench02RootApp() {
+    gROOT->SetBatch(kTRUE);
     if (!gApplication) {
         int argc = 1;
         char* argv[1]; argv[0] = (char*)appname;
diff --git a/pypy/module/cppyy/bench/hsimple.C b/pypy/module/cppyy/bench/hsimple.C
--- a/pypy/module/cppyy/bench/hsimple.C
+++ b/pypy/module/cppyy/bench/hsimple.C
@@ -14,6 +14,7 @@
 
 TFile *hsimple(Int_t get=0)
 {
+   gROOT->SetBatch();
 //  This program creates :
 //    - a one dimensional histogram
 //    - a two dimensional histogram
@@ -26,14 +27,14 @@
 //  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
@@ -60,10 +61,11 @@
    }
    hfile = (TFile*)gROOT->FindObject(filename); if (hfile) hfile->Close();
 */
-   hfile = new TFile(filename,"RECREATE","Demo ROOT file with histograms");
+//   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->Print();
 /*
    hpx->SetFillColor(48);
    TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
@@ -111,7 +113,8 @@
    hpx->SetFillColor(48);
    c1->Modified();
 */
-   return hfile;
+   hpx->Print();
+   return 0;//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
--- a/pypy/module/cppyy/bench/hsimple.py
+++ b/pypy/module/cppyy/bench/hsimple.py
@@ -11,22 +11,26 @@
 #*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
 
 try:
-   import cppyy, random
-   cppyy.load_lib('bench02Dict_reflex.so')
+    import warnings
+    warnings.simplefilter("ignore")
 
-   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
+    import cppyy, random
+    cppyy.load_lib('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
+    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
@@ -49,10 +53,11 @@
 #hfile = gROOT.FindObject( 'hsimple.root' )
 #if hfile:
 #   hfile.Close()
-hfile = TFile( 'hsimple.root', 'RECREATE', 'Demo ROOT file with histograms' )
+#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    = 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' )
@@ -66,22 +71,23 @@
 #gRandom.SetSeed()
 #rannor, rndm = gRandom.Rannor, gRandom.Rndm
 
-#random = TRandom()
+random = TRandom()
+random.SetSeed(0)
 
 # Fill histograms randomly.
 #px, py = Double(), Double()
 kUPDATE = 1000
-for i in xrange( 2500000 ):
+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)
+#   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 )
+   hpx.Fill(pt)
 #   hpxpyFill( px, py )
 #   hprofFill( px, pz )
 #   ntupleFill( px, py, pz, random, i )
@@ -99,16 +105,16 @@
 
 #gBenchmark.Show( 'hsimple' )
 
+hpx.Print() 
+
 # Save all objects in this file.
 #hpx.SetFillColor( 0 )
 #hfile.Write()
-hfile.Close()
+#hfile.Close()
 #hpx.SetFillColor( 48 )
 #c1.Modified()
 #c1.Update()
 #c1.Draw()
-#import gc
-#gc.collect()
-  
+
 # Note that the file is automatically closed when application terminates
 # or when the file destructor is called.


More information about the pypy-commit mailing list