[pypy-commit] pypy reflex-support: enable hsimple.py in its full glory (note that it is now no longer completely CPU-bound, so less useful as a true benchmark, but fun nevertheless)
wlav
noreply at buildbot.pypy.org
Tue Mar 20 23:37:10 CET 2012
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r53843:54eff2de135e
Date: 2012-03-20 14:34 -0700
http://bitbucket.org/pypy/pypy/changeset/54eff2de135e/
Log: enable hsimple.py in its full glory (note that it is now no longer
completely CPU-bound, so less useful as a true benchmark, but fun
nevertheless)
diff --git a/pypy/module/cppyy/bench/hsimple.C b/pypy/module/cppyy/bench/hsimple.C
old mode 100755
new mode 100644
--- a/pypy/module/cppyy/bench/hsimple.C
+++ b/pypy/module/cppyy/bench/hsimple.C
@@ -6,15 +6,12 @@
#include <TFrame.h>
#include <TROOT.h>
#include <TSystem.h>
-#include <TRandom.h>
+#include <TRandom3.h>
#include <TBenchmark.h>
#include <TInterpreter.h>
-#include <math.h>
-
TFile *hsimple(Int_t get=0)
{
- gROOT->SetBatch();
// This program creates :
// - a one dimensional histogram
// - a two dimensional histogram
@@ -27,14 +24,11 @@
// 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,13 +54,10 @@
return 0;
}
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);
TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
@@ -81,20 +72,21 @@
c1->GetFrame()->SetBorderSize(6);
c1->GetFrame()->SetBorderMode(-1);
-*/
+
// Fill histograms randomly
- gRandom->SetSeed();
- Float_t px, py, pt;
+ TRandom3 random;
+ Float_t px, py, pz;
const Int_t kUPDATE = 1000;
- for (Int_t i = 0; i < 2500000; i++) {
- gRandom->Rannor(px,py);
- pt = sqrt(px*px + py*py);
- // Float_t random = gRandom->Rndm(1);
- hpx->Fill(pt);
-/*
+ 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,random,i);
+ ntuple->Fill(px,py,pz,rnd,i);
if (i && (i%kUPDATE) == 0) {
if (i == kUPDATE) hpx->Draw();
c1->Modified();
@@ -102,9 +94,7 @@
if (gSystem->ProcessEvents())
break;
}
-*/
}
-/*
gBenchmark->Show("hsimple");
// Save all objects in this file
@@ -112,9 +102,7 @@
hfile->Write();
hpx->SetFillColor(48);
c1->Modified();
-*/
- hpx->Print();
- return 0;//hfile;
+ 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
--- a/pypy/module/cppyy/bench/hsimple.py
+++ b/pypy/module/cppyy/bench/hsimple.py
@@ -11,110 +11,87 @@
#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
try:
- import warnings
- warnings.simplefilter("ignore")
+ import cppyy, random
- 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
+ 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, TRandom
+ from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F, TRandom3
+ from ROOT import gROOT, gBenchmark, gSystem
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' )
+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' )
+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)
+ntuple = TNtuple('ntuple', 'Demo ntuple', 'px:py:pz:random:i')
-# Set canvas/frame attributes.
-#hpx.SetFillColor( 48 )
+gBenchmark.Start('hsimple')
-#gBenchmark.Start( 'hsimple' )
-
-# Initialize random number generator.
-#gRandom.SetSeed()
-#rannor, rndm = gRandom.Rannor, gRandom.Rndm
-
-random = TRandom()
-random.SetSeed(0)
+# 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.
-#px, py = Double(), Double()
+random = TRandom3()
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)
+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(pt)
-# hpxpyFill( px, py )
-# hprofFill( px, pz )
-# ntupleFill( px, py, pz, random, i )
+ # Fill histograms
+ hpx.Fill(px)
+ hpxpy.Fill(px, py)
+ hprof.Fill(px, pz)
+ ntuple.Fill(px, py, pz, rnd, i)
- # Update display every kUPDATE events.
-# if i and i%kUPDATE == 0:
-# if i == kUPDATE:
-# hpx.Draw()
+ # Update display every kUPDATE events
+ if i and i%kUPDATE == 0:
+ if i == kUPDATE:
+ hpx.Draw()
-# c1.Modified()
-# c1.Update()
+ c1.Modified()
+ c1.Update()
-# if gSystem.ProcessEvents(): # allow user interrupt
-# break
+ if gSystem.ProcessEvents(): # allow user interrupt
+ break
-#gBenchmark.Show( 'hsimple' )
+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()
+# Save all objects in this file
+hpx.SetFillColor(0)
+hfile.Write()
+hpx.SetFillColor(48)
+c1.Modified()
+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
new file mode 100755
--- /dev/null
+++ b/pypy/module/cppyy/bench/hsimple_rflx.py
@@ -0,0 +1,120 @@
+#*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+#*-*
+#*-* 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.
More information about the pypy-commit
mailing list