BmnRoot
Loading...
Searching...
No Matches
L1Timer.h
Go to the documentation of this file.
1#ifndef _L1Timer_H
2#define _L1Timer_H
3
4/*
5 *=====================================================
6 *
7 * Authors: I.Kulakov
8 *
9 */
10
11#include "TStopwatch.h"
12
13#include <iostream>
14#include <iomanip>
15#include <string>
16#include <vector>
17
18using std::cout;
19using std::endl;
20using std::ios;
21using std::setw;
22using std::string;
23using std::vector;
24
25class TimerInfo {
26 public:
27 TimerInfo():fName(""),fReal(0.),fCpu(0.){ };
28 TimerInfo( const string& name ):fName(name),fReal(0.),fCpu(0.){ };
29
30 void operator =( TStopwatch& sw ) { fReal = sw.RealTime(); fCpu = sw.CpuTime(); };
31 void operator+=( TStopwatch& sw ) { fReal += sw.RealTime(); fCpu += sw.CpuTime(); };
32 void operator+=( const TimerInfo& t ){ fReal += t.fReal; fCpu += t.fCpu; }
33 TimerInfo operator/( const float f ) const { TimerInfo r; r.fName = fName; r.fReal = fReal/f; r.fCpu = fCpu/f; return r; }
34
35 // void Print(){ cout << fReal << "/" << fCpu; };
36 void PrintReal(){ cout << fReal ; };
37 float Real(){ return fReal; };
38 string& Name(){ return fName; };
39 private:
40 string fName;
41 float fReal, fCpu;
42};
43
45 public:
46 L1CATFIterTimerInfo() : fNameToI(), fTIs() {}
47 void Add( string name ) { fNameToI[name] = fTIs.size(); fTIs.push_back(TimerInfo(name)); };
48 TimerInfo& operator[]( string name ) { return fTIs[fNameToI[name]]; };
49 TimerInfo& operator[]( int i ) { return fTIs[i]; };
50 void operator+=( L1CATFIterTimerInfo& t ){ for( unsigned int i = 0; i < fTIs.size(); ++i ) fTIs[i] += t[i]; }
53 r.fNameToI = fNameToI;
54 r.fTIs.resize(fTIs.size());
55 for( unsigned int i = 0; i < fTIs.size(); ++i ) {
56 r.fTIs[i] = fTIs[i]/f;
57 }
58 return r;
59 }
60
61 void PrintReal( int f = 0 ){
62 if (f) { PrintNames(); cout << endl; }
63 fTIs[0].PrintReal(); for( unsigned int i = 1; i < fTIs.size(); ++i ) { cout << " | " << setw(fTIs[i].Name().size()); fTIs[i].PrintReal(); }
64 if (f) cout << endl;
65 };
66 void PrintNames(){ cout << fTIs[0].Name(); for( unsigned int i = 1; i < fTIs.size(); ++i ) { cout << " | " << fTIs[i].Name(); } };
67 private:
68 map< string, int > fNameToI;
69 vector<TimerInfo> fTIs;
70};
71
73 public:
74 L1CATFTimerInfo() : fTIIs(), fTIAll() {};
75 void SetNIter( int n ) { fTIIs.resize(n); };
76
77 void Add( string name ) {
78 for( unsigned int i = 0; i < fTIIs.size(); ++i )
79 fTIIs[i].Add(name);
80 fTIAll.Add(name);
81 }; // use after setniter
82 L1CATFIterTimerInfo& GetTimerAll() { return fTIAll; };
83 L1CATFIterTimerInfo& operator[]( int i ) { return fTIIs[i]; };
84 void operator+=( L1CATFTimerInfo& t ){ for( unsigned int i = 0; i < fTIIs.size(); ++i ) fTIIs[i] += t[i]; fTIAll += t.GetAllInfo(); }
87 r.fTIAll = fTIAll/f;
88 r.SetNIter( fTIIs.size() );
89 for( unsigned int i = 0; i < fTIIs.size(); ++i ) {
90 r.fTIIs[i] = fTIIs[i]/f;
91 }
92 return r;
93 }
94
95 void Calc() {
96 fTIAll = fTIIs[0];
97 for( unsigned int i = 1; i < fTIIs.size(); ++i )
98 fTIAll += fTIIs[i];
99 }
100
101 L1CATFIterTimerInfo& GetAllInfo() { return fTIAll; };
102 void PrintReal() {
103 cout.precision(1);
104 cout.setf(ios::fixed);
105 cout << " stage "<< " : "; fTIAll.PrintNames(); cout << endl;
106 for( unsigned int i = 0; i < fTIIs.size(); ++i ) {
107 cout << " iter " << i << " : "; fTIIs[i].PrintReal(); cout << endl;
108 }
109 cout << " all "<< " : "; fTIAll.PrintReal(); cout << endl;
110
111 };
112 private:
113 vector<L1CATFIterTimerInfo> fTIIs;
114 L1CATFIterTimerInfo fTIAll;
115};
116
117#endif
118
int i
Definition P4_F32vec4.h:22
float f
Definition P4_F32vec4.h:21
TimerInfo & operator[](string name)
Definition L1Timer.h:48
void PrintReal(int f=0)
Definition L1Timer.h:61
void Add(string name)
Definition L1Timer.h:47
void operator+=(L1CATFIterTimerInfo &t)
Definition L1Timer.h:50
L1CATFIterTimerInfo operator/(float f)
Definition L1Timer.h:51
TimerInfo & operator[](int i)
Definition L1Timer.h:49
void Add(string name)
Definition L1Timer.h:77
L1CATFTimerInfo operator/(float f)
Definition L1Timer.h:85
L1CATFIterTimerInfo & GetAllInfo()
Definition L1Timer.h:101
void operator+=(L1CATFTimerInfo &t)
Definition L1Timer.h:84
L1CATFIterTimerInfo & GetTimerAll()
Definition L1Timer.h:82
L1CATFIterTimerInfo & operator[](int i)
Definition L1Timer.h:83
void PrintReal()
Definition L1Timer.h:102
void Calc()
Definition L1Timer.h:95
void SetNIter(int n)
Definition L1Timer.h:75
TimerInfo operator/(const float f) const
Definition L1Timer.h:33
string & Name()
Definition L1Timer.h:38
void operator=(TStopwatch &sw)
Definition L1Timer.h:30
TimerInfo()
Definition L1Timer.h:27
void PrintReal()
Definition L1Timer.h:36
void operator+=(TStopwatch &sw)
Definition L1Timer.h:31
TimerInfo(const string &name)
Definition L1Timer.h:28
float Real()
Definition L1Timer.h:37
void operator+=(const TimerInfo &t)
Definition L1Timer.h:32