#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 RunTest(const char* name, const char* title, int BufferSize) { TH1D* histoRes = new TH1D(name, title, 10, 0.5, 10.5); histoRes->GetXaxis()->SetTitle("Number of active branches"); histoRes->GetYaxis()->SetTitle("Real time (s)"); histoRes->SetDirectory(0); histoRes->SetStats(kFALSE); ProduceTree("TreeFile.root","TestTree", 1000000, 0, 10, 10, BufferSize); Float_t RealTime, CpuTime; for(int ActiveBranches=1;ActiveBranches<=10;ActiveBranches++) { PurgeMemory(); cout << "Buffer size = " << BufferSize*80 << " ActiveBranches = " << ActiveBranches << endl; MakeDelay(5); TestTree("TreeFile.root","TestTree", 10, 10, ActiveBranches, RealTime, CpuTime); histoRes->SetBinContent(ActiveBranches, RealTime); } TCanvas* c1 = new TCanvas(TString(name)+"_canvas",title); histoRes->Draw(); } void ShortTest() { RunTest("LargeBuffer","1000000 events, 10 brunches, 10 doubles in brunch, Basket size = 80000", 1000); RunTest("SmallBuffer","1000000 events, 10 brunches, 10 doubles in brunch, Basket size = 80", 1); }