Logo ROOT  
Reference Guide
bill.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tree
3/// \notebook -nodraw
4/// Benchmark comparing row-wise and column-wise storage performance
5///
6/// The test consists in writing/reading to/from keys or trees
7/// To execute the benchmark:
8/// ~~~
9/// root -b -q bill.C or root -b -q bill.C++
10/// ~~~
11/// for example for N=10000, the following output is produced
12/// on an 2.7 GHz Intel Core i7 (year 2011).
13/// The names featuring a "t" are relative to trees, the faster, the better.
14/// ~~~
15/// billw0 : RT= 0.803 s, Cpu= 0.800 s, File size= 45608143 bytes, CX= 1
16/// billr0 : RT= 0.388 s, Cpu= 0.390 s
17/// billtw0 : RT= 0.336 s, Cpu= 0.310 s, File size= 45266881 bytes, CX= 1.00034
18/// billtr0 : RT= 0.229 s, Cpu= 0.230 s
19/// billw1 : RT= 1.671 s, Cpu= 1.670 s, File size= 16760526 bytes, CX= 2.72078
20/// billr1 : RT= 0.667 s, Cpu= 0.680 s
21/// billtw1 : RT= 0.775 s, Cpu= 0.770 s, File size= 9540884 bytes, CX= 4.74501
22/// billtr1 : RT= 0.352 s, Cpu= 0.350 s
23/// billtot : RT= 5.384 s, Cpu= 5.290 s
24/// ******************************************************************
25/// * ROOTMARKS =1763.9 * Root6.05/03 20150914/948
26/// ******************************************************************
27/// ~~~
28/// \macro_code
29/// \author Rene Brun
30
31#include "TFile.h"
32#include "TSystem.h"
33#include "TH1.h"
34#include "TRandom.h"
35#include "TStopwatch.h"
36#include "TKey.h"
37#include "TTree.h"
38#include "TROOT.h"
39
40const Int_t N = 10000; //number of events to be processed
41TStopwatch timer;
42
43
44
45void billw(const char *billname, Int_t compress) {
46 //write N histograms as keys
47 timer.Start();
48 TFile f(billname,"recreate","bill benchmark with keys",compress);
49 TH1F h("h","h",1000,-3,3);
50 h.FillRandom("gaus",50000);
51
52 for (Int_t i=0;i<N;i++) {
53 char name[20];
54 sprintf(name,"h%d",i);
55 h.SetName(name);
56 h.Fill(2*gRandom->Rndm());
57 h.Write();
58 }
59 timer.Stop();
60 printf("billw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
61 (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
62}
63
64void billr(const char *billname, Int_t compress) {
65 //read N histograms from keys
66 timer.Start();
67 TFile f(billname);
68 TIter next(f.GetListOfKeys());
69 TH1F *h;
71 TKey *key;
72 Int_t i=0;
73 TH1F *hmean = new TH1F("hmean","hist mean from keys",100,0,1);
74
75 while ((key=(TKey*)next())) {
76 h = (TH1F*)key->ReadObj();
77 hmean->Fill(h->GetMean());
78 delete h;
79 i++;
80 }
81 timer.Stop();
82 printf("billr%d : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
83}
84
85void billtw(const char *billtname, Int_t compress) {
86 //write N histograms to a Tree
87 timer.Start();
88 TFile f(billtname,"recreate","bill benchmark with trees",compress);
89 TH1F *h = new TH1F("h","h",1000,-3,3);
90 h->FillRandom("gaus",50000);
91 TTree *T = new TTree("T","test bill");
92 T->Branch("event","TH1F",&h,64000,0);
93 for (Int_t i=0;i<N;i++) {
94 char name[20];
95 sprintf(name,"h%d",i);
96 h->SetName(name);
97 h->Fill(2*gRandom->Rndm());
98 T->Fill();
99 }
100 T->Write();
101 delete T;
102 timer.Stop();
103 printf("billtw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
104 (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
105}
106
107void billtr(const char *billtname, Int_t compress) {
108 //read N histograms from a tree
109 timer.Start();
110 TFile f(billtname);
111 TH1F *h = 0;
112 TTree *T = (TTree*)f.Get("T");
113 T->SetBranchAddress("event",&h);
114 TH1F *hmeant = new TH1F("hmeant","hist mean from tree",100,0,1);
115 Long64_t nentries = T->GetEntries();
116 for (Long64_t i=0;i<nentries;i++) {
117 T->GetEntry(i);
118 hmeant->Fill(h->GetMean());
119 }
120 timer.Stop();
121 printf("billtr%d : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
122}
123
124void bill() {
125
126 TString dir = gSystem->GetDirName(gSystem->UnixPathName(__FILE__));
127 TString bill = dir + "/bill.root";
128 TString billt = dir + "/billt.root";
129
130 TStopwatch totaltimer;
131 totaltimer.Start();
132 for (Int_t compress=0;compress<2;compress++) {
133 billw(bill,compress);
134 billr(bill,compress);
135 billtw(billt,compress);
136 billtr(billt,compress);
137 }
138 gSystem->Unlink(bill);
139 gSystem->Unlink(billt);
140 totaltimer.Stop();
141 Double_t realtime = totaltimer.RealTime();
142 Double_t cputime = totaltimer.CpuTime();
143 printf("billtot : RT=%7.3f s, Cpu=%7.3f s\n",realtime,cputime);
144 //reference is a P IV 2.4 GHz
145 Float_t rootmarks = 600*(16.98 + 14.40)/(realtime + cputime);
146 printf("******************************************************************\n");
147 printf("* ROOTMARKS =%6.1f * Root%-8s %d/%d\n",rootmarks,gROOT->GetVersion(),gROOT->GetVersionDate(),gROOT->GetVersionTime());
148 printf("******************************************************************\n");
149}
150
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
double Double_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:80
#define N
char name[80]
Definition: TGX11.cxx:110
int nentries
Definition: THbookFile.cxx:91
#define gROOT
Definition: TROOT.h:404
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:574
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition: TH1.cxx:1267
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3338
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:28
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:750
Double_t Rndm() override
Machine independent random number generator.
Definition: TRandom.cxx:552
Stopwatch class.
Definition: TStopwatch.h:28
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:110
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:125
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:77
Basic string class.
Definition: TString.h:136
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition: TSystem.cxx:1063
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1032
virtual int Unlink(const char *name)
Unlink, i.e.
Definition: TSystem.cxx:1381
A TTree represents a columnar dataset.
Definition: TTree.h:79
double T(double x)
Definition: ChebyshevPol.h:34