#include #include "TTree.h" #include "TFile.h" #include "TCanvas.h" #include "TBranch.h" #include "TBenchmark.h" #include "TSystem.h" #include "TH1.h" #include "TH2.h" void MakeDelay(int time_in_sec) { gSystem->Sleep(time_in_sec*1000); } void PurgeMemory(bool show = false) { const int RAMSIZE = 512; if (show) cout << "Purge " << RAMSIZE << " MB of memory" << endl; Double_t** buffers = (Double_t**) malloc(RAMSIZE*4); for(int n=0;nSetBranchAddress(brname,&(data[nbr*branchsize])); } if (activebranches<=0) t->SetBranchStatus("*",1); else { t->SetBranchStatus("*",0); for (int nbr=0;nbrSetBranchStatus(brname,1); } } Int_t counter = 0; gBenchmark->Reset(); gBenchmark->Start("TestTree"); while (t->GetEntry(counter++)); gBenchmark->Stop("TestTree"); gBenchmark->Show("TestTree"); RealTime = gBenchmark->GetRealTime("TestTree"); CpuTime = gBenchmark->GetCpuTime("TestTree"); delete[] data; } void SingleTest(const char* filename, const char* treename, int NumBranches, int NumBuffersStep, Int_t NumberOfEvents, Int_t SizeOfBranch) { TFile f(filename,"recreate"); TTree t(treename,"results of tree perfomance measurements"); Int_t BufferSize, ActiveBranches; Float_t RealTime, CpuTime; t.Branch("BufferSize",&BufferSize,"BufferSize/I"); t.Branch("ActiveBranches",&ActiveBranches,"ActiveBranches/I"); t.Branch("RealTime",&RealTime,"RealTime/F"); t.Branch("CpuTime",&CpuTime,"CpuTime/F"); BufferSize = 1; for(int bufcounter=0;bufcounterSetBranchAddress("BufferSize",&BufferSize); t->SetBranchAddress("ActiveBranches",&ActiveBranches); t->SetBranchAddress("RealTime",&RealTime); t->SetBranchAddress("CpuTime",&CpuTime); TH2D* histoReal = new TH2D("RealTime",TString(HistogramTitle) + " Real time", NumBranches,0.5,0.5+NumBranches,NumBuffersStep,-0.5,-0.5+NumBuffersStep); histoReal->GetXaxis()->SetTitle("number of active branches"); histoReal->GetYaxis()->SetTitle("relative buffer size (logarithm)"); histoReal->GetZaxis()->SetTitle("time (s)"); histoReal->SetDirectory(0); histoReal->SetStats(kFALSE); TH2D* histoCPU = new TH2D("CPUtime",TString(HistogramTitle) + " CPU time", NumBranches,0.5,0.5+NumBranches,NumBuffersStep,-0.5,-0.5+NumBuffersStep); histoCPU->GetXaxis()->SetTitle("number of active branches"); histoCPU->GetYaxis()->SetTitle("relative buffer size (logarithm)"); histoCPU->GetYaxis()->SetTitle("time (s)"); histoCPU->SetDirectory(0); histoCPU->SetStats(kFALSE); int counter=0; while (t->GetEntry(counter++)) { float value = TMath::Log(BufferSize)/TMath::Log(2.); histoReal->Fill(ActiveBranches,value,RealTime); histoCPU->Fill(ActiveBranches,value,CpuTime); } TString cname(CanvasName); TCanvas* c1 = new TCanvas(cname+"_Real","Results of tree tests"); c1->SetPhi(145); c1->SetTheta(15); histoReal->Draw("LEGO"); c1->SaveAs(cname+"_Real.gif"); // TCanvas* c2 = new TCanvas(cname+"_CPU","Results of tree tests"); // c2->SetPhi(145); // c2->SetTheta(15); // histoCPU->Draw("LEGO"); // c2->SaveAs(cname+"_CPU.gif"); } void PerfomanceTest() { SingleTest("Tree_small.root","Perfomance", 10,10, 1000000, 10); // 1000000 events x 10 branches x 10 doubles/branch SingleTest("Tree_large.root","Perfomance", 10,10, 10000, 1000); // 10000 events x 10 branches x 1000 doubles/branch ShowTestResults("Tree_small.root","Perfomance","Tree_small","1000000 events x 10 branches x 10 doubles/branch", 10,10); ShowTestResults("Tree_large.root","Perfomance","Tree_large","10000 events x 10 branches x 1000 doubles/branch", 10,10); }