ROOT  6.06/09
Reference Guide
TestTimer.h
Go to the documentation of this file.
1 #ifndef TESTTIMER_H
2 #define TESTTIMER_H
3 
4 // simple class to measure time
5 
6 #include "TStopwatch.h"
7 
8 
9 namespace ROOT {
10 
11  namespace Math{
12 
13  namespace test {
14 
15 #ifdef REPORT_TIME
16  void reportTime( std::string s, double time);
17 #endif
18 
19  void printTime(TStopwatch & time, std::string s) {
20  int pr = std::cout.precision(8);
21  std::cout << s << "\t" << " time = " << time.RealTime() << "\t(sec)\t"
22  // << time.CpuTime()
23  << std::endl;
24  std::cout.precision(pr);
25  }
26 
27 
28 
29  class Timer {
30 
31  public:
32 
33  Timer(const std::string & s = "") : fName(s), fTime(0)
34  {
35  fWatch.Start();
36  }
37  Timer(double & t, const std::string & s = "") : fName(s), fTime(&t)
38  {
39  fWatch.Start();
40  }
41 
42  ~Timer() {
43  fWatch.Stop();
45 #ifdef REPORT_TIME
46  // report time
47  reportTime(fName, fWatch.RealTime() );
48 #endif
49  if (fTime) *fTime += fWatch.RealTime();
50  }
51 
52 
53  private:
54 
55  std::string fName;
56  double * fTime;
58 
59  };
60  }
61 
62  }
63 }
64 
65 #endif
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:108
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:56
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Timer(double &t, const std::string &s="")
Definition: TestTimer.h:37
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:75
void printTime(TStopwatch &time, std::string s)
Definition: TestTimer.h:19
RooCmdArg Timer(Bool_t flag=kTRUE)
Timer(const std::string &s="")
Definition: TestTimer.h:33
Namespace for new Math classes and functions.
Stopwatch class.
Definition: TStopwatch.h:30