1 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
2 //*-- Copyright © Uli
6 #include "TGraphAsymmErrors.h"
8 #include "TStopwatch.h"
9 #include "AliL3Benchmark.h"
10 #include "TStopwatch.h"
12 #include "AliL3Logging.h"
15 //_____________________________________________________________
17 // Benchmark class for level3 code
22 ClassImp(AliL3Benchmark)
23 AliL3Benchmark::AliL3Benchmark()
38 AliL3Benchmark::~AliL3Benchmark()
41 if (fNames) {delete [] fNames; fNames = 0;}
42 if (fTimer) {delete [] fTimer; fTimer = 0;}
43 if (fSum) {delete [] fSum; fSum = 0;}
44 if (fMin) {delete [] fMin; fMin = 0;}
45 if (fMax) {delete [] fMax; fMax = 0;}
46 if (fCount) {delete [] fCount; fCount =0;}
47 // if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
50 Int_t AliL3Benchmark::GetBench(const char *name)
52 for (Int_t i=0;i<fNbench;i++) {
53 if (!strcmp(name,(const char*)fNames[i])) return i;
59 void AliL3Benchmark::Start(const char *name)
62 fNames = new TString[fNmax];
63 fTimer = new TStopwatch[fNmax];
64 fSum = new Float_t[fNmax];
65 fMin = new Float_t[fNmax];
66 fMax = new Float_t[fNmax];
67 fCount = new Int_t[fNmax];
68 for(Int_t i =0;i<fNmax;i++){
75 Int_t bench = GetBench(name);
76 if (bench < 0 && fNbench < fNmax ) {
77 // define a new benchmark to Start
78 fNames[fNbench] = name;
81 fTimer[bench].Reset();
82 fTimer[bench].Start();
83 // if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
84 // fStopwatch = new TStopwatch();
85 // fStopwatch->Reset();
86 // fStopwatch->Start();
87 } else if (bench >=0) {
88 // Resume the existen benchmark
89 fTimer[bench].Reset();
90 fTimer[bench].Start();
91 // if(fStopwatch) {delete fStopwatch; fStopwatch =0;}
92 // fStopwatch = new TStopwatch();
93 // fStopwatch->Reset();
94 // fStopwatch->Start();
97 LOG(AliL3Log::kWarning,"AliL3Benchmark::Start","Start")
98 <<"too many benches"<<ENDLOG;
101 void AliL3Benchmark::Stop(const char *name)
103 Int_t bench = GetBench(name);
104 if (bench < 0) return;
106 fTimer[bench].Stop();
107 Float_t val = fTimer[bench].CpuTime();
108 // fStopwatch->Stop();
109 // Float_t val = fStopwatch->CpuTime();
113 if(fCount[bench]==1){
118 if(val<fMin[bench])fMin[bench]=val;
119 if(val>fMax[bench])fMax[bench]=val;
123 void AliL3Benchmark::Analyze(const char* name){
124 Float_t *x = new Float_t[fNbench];
125 Float_t *y = new Float_t[fNbench];
126 Float_t *eyl = new Float_t[fNbench];
127 Float_t *eyh = new Float_t[fNbench];
129 sprintf(filename,"%s.dat",name);
130 FILE *f= fopen(filename,"w");
131 for (Int_t i=0;i<fNbench;i++) {
133 if(fCount[i]) av = fSum[i]/fCount[i];
136 eyl[i]=(av-fMin[i])*1000;
137 eyh[i]=(fMax[i]-av)*1000;
138 fprintf(f,"%2d. %s: ",i+1,fNames[i].Data());
139 fprintf(f,"%4.0f ms\n",av*1000);
142 sprintf(filename,"%s.tmp",name);
143 /* only a workaround!!
144 FILE *f2= fopen(filename,"w");
145 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",x[i]); fprintf(f2,"\n");
146 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",y[i]); fprintf(f2,"\n");
147 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyl[i]); fprintf(f2,"\n");
148 for (Int_t i=0;i<fNbench;i++) fprintf(f2,"%f ",eyh[i]); fprintf(f2,"\n");
151 sprintf(filename,"%s.root",name);
152 TFile *file = new TFile(filename,"RECREATE");
153 TGraphAsymmErrors *gr = new TGraphAsymmErrors(fNbench,x,y,0,0,eyl,eyh);
154 gr->SetTitle("benchmark");
155 gr->SetMarkerStyle(8);
168 Double_t AliL3Benchmark::GetCpuTime()
170 {return (Double_t)(clock()) / CLOCKS_PER_SEC;}