bill.C

Go to the documentation of this file.
00001 // benchmark comparing write/read to/from keys or trees
00002 // for example for N=10000, the following output is produced
00003 // on a P IV 62.4GHz
00004 //   
00005 // root -b -q bill.C    or root -b -q bill.C++
00006 //
00007 //billw0  : RT=  1.070 s, Cpu=  1.050 s, File size=  45508003 bytes, CX= 1
00008 //billr0  : RT=  0.740 s, Cpu=  0.730 s
00009 //billtw0 : RT=  0.720 s, Cpu=  0.660 s, File size=  45163959 bytes, CX= 1
00010 //billtr0 : RT=  0.420 s, Cpu=  0.420 s
00011 //billw1  : RT=  6.600 s, Cpu=  6.370 s, File size=  16215349 bytes, CX= 2.80687
00012 //billr1  : RT=  2.290 s, Cpu=  2.270 s
00013 //billtw1 : RT=  3.260 s, Cpu=  3.230 s, File size=   6880273 bytes, CX= 6.5642
00014 //billtr1 : RT=  0.990 s, Cpu=  0.980 s
00015 //billtot : RT= 18.290 s, Cpu= 15.920 s
00016 //******************************************************************
00017 //*  ROOTMARKS = 600.9   *  Root3.05/02   20030201/1840
00018 //******************************************************************
00019 //
00020 //Author: Rene Brun
00021 
00022 #include "TFile.h"
00023 #include "TSystem.h"
00024 #include "TH1.h"
00025 #include "TRandom.h"
00026 #include "TStopwatch.h"
00027 #include "TKey.h"
00028 #include "TTree.h"
00029    
00030 const Int_t N = 10000;       //number of events to be processed
00031 TStopwatch timer;
00032 
00033 void billw(Int_t compress) {
00034    //write N histograms as keys
00035    timer.Start();
00036    TFile f("/tmp/bill.root","recreate","bill benchmark with keys",compress);
00037    TH1F h("h","h",1000,-3,3);
00038    h.FillRandom("gaus",50000);
00039    
00040    for (Int_t i=0;i<N;i++) {
00041       char name[20];
00042       sprintf(name,"h%d",i);
00043       h.SetName(name);
00044       h.Fill(2*gRandom->Rndm());
00045       h.Write();
00046    }
00047    timer.Stop();
00048    printf("billw%d  : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
00049                     (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
00050    }
00051 void billr(Int_t compress) {
00052    //read N histograms from keys
00053    timer.Start();
00054    TFile f("/tmp/bill.root");
00055    TIter next(f.GetListOfKeys());
00056    TH1F *h;
00057    TH1::AddDirectory(kFALSE);
00058    TKey *key;
00059    Int_t i=0;
00060    TH1F *hmean = new TH1F("hmean","hist mean from keys",100,0,1);
00061    
00062    while ((key=(TKey*)next())) {
00063       h = (TH1F*)key->ReadObj();
00064       hmean->Fill(h->GetMean());
00065       delete h;
00066       i++;
00067    }
00068    timer.Stop();
00069    printf("billr%d  : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
00070 }
00071 void billtw(Int_t compress) {
00072    //write N histograms to a Tree
00073    timer.Start();
00074    TFile f("/tmp/billt.root","recreate","bill benchmark with trees",compress);
00075    TH1F *h = new TH1F("h","h",1000,-3,3);
00076    h->FillRandom("gaus",50000);
00077    TTree *T = new TTree("T","test bill");
00078    T->Branch("event","TH1F",&h,64000,0);
00079    for (Int_t i=0;i<N;i++) {
00080       char name[20];
00081       sprintf(name,"h%d",i);
00082       h->SetName(name);
00083       h->Fill(2*gRandom->Rndm());
00084       T->Fill();
00085    }
00086    T->Write();
00087    delete T;
00088    timer.Stop();
00089    printf("billtw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
00090                     (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
00091 }
00092 void billtr(Int_t compress) {
00093    //read N histograms from a tree
00094    timer.Start();
00095    TFile f("/tmp/billt.root");
00096    TH1F *h = 0;
00097    TTree *T = (TTree*)f.Get("T");
00098    T->SetBranchAddress("event",&h);
00099    TH1F *hmeant = new TH1F("hmeant","hist mean from tree",100,0,1);
00100    Int_t nentries = (Int_t)T->GetEntries();
00101    for (Int_t i=0;i<nentries;i++) {
00102       T->GetEntry(i);
00103       hmeant->Fill(h->GetMean());
00104    }
00105    timer.Stop();
00106    printf("billtr%d : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
00107 }
00108 void bill() {
00109    
00110    TStopwatch totaltimer;
00111    totaltimer.Start();
00112    for (Int_t compress=0;compress<2;compress++) {
00113       billw(compress);
00114       billr(compress);
00115       billtw(compress);
00116       billtr(compress);
00117    }
00118    gSystem->Unlink("/tmp/bill.root");
00119    gSystem->Unlink("/tmp/billt.root");
00120    totaltimer.Stop();
00121    Double_t rtime = totaltimer.RealTime();
00122    Double_t ctime = totaltimer.CpuTime();
00123    printf("billtot : RT=%7.3f s, Cpu=%7.3f s\n",rtime,ctime);
00124    //reference is a P IV 2.4 GHz
00125    Float_t rootmarks = 600*(16.98 + 14.40)/(rtime + ctime);
00126    printf("******************************************************************\n");
00127    printf("*  ROOTMARKS =%6.1f   *  Root%-8s  %d/%d\n",rootmarks,gROOT->GetVersion(),gROOT->GetVersionDate(),gROOT->GetVersionTime());
00128    printf("******************************************************************\n");
00129 }
00130           

Generated on Tue Jul 5 15:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1