TestTimer.h

Go to the documentation of this file.
00001 #ifndef TESTTIMER_H
00002 #define TESTTIMER_H
00003 
00004 // simple class to measure time 
00005 
00006 #include "TStopwatch.h"
00007 
00008 
00009 namespace ROOT { 
00010 
00011   namespace Math{ 
00012 
00013     namespace test { 
00014 
00015 #ifdef REPORT_TIME
00016       void reportTime( std::string s, double time); 
00017 #endif
00018 
00019       void printTime(TStopwatch & time, std::string s) { 
00020         int pr = std::cout.precision(8);
00021         std::cout << s << "\t" << " time = " << time.RealTime() << "\t(sec)\t" 
00022           //    << time.CpuTime() 
00023                   << std::endl;
00024         std::cout.precision(pr);
00025       }
00026 
00027 
00028 
00029       class Timer {
00030 
00031       public: 
00032 
00033         Timer(const std::string & s = "") : fName(s), fTime(0) 
00034         {
00035           fWatch.Start();
00036         }
00037         Timer(double & t, const std::string & s = "") : fName(s), fTime(&t) 
00038         {
00039           fWatch.Start();
00040         } 
00041         
00042         ~Timer() { 
00043           fWatch.Stop();
00044           printTime(fWatch,fName);
00045 #ifdef REPORT_TIME
00046           // report time
00047           reportTime(fName, fWatch.RealTime() );
00048 #endif
00049           if (fTime) *fTime += fWatch.RealTime();
00050         }
00051 
00052 
00053       private: 
00054         
00055         std::string fName;
00056         double * fTime; 
00057         TStopwatch fWatch; 
00058         
00059       }; 
00060     }
00061 
00062   }
00063 }
00064 
00065 #endif

Generated on Tue Jul 5 14:43:22 2011 for ROOT_528-00b_version by  doxygen 1.5.1