5 =================================================
7 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
8 * @date 18 Jul 2007 16:27:45
13 =================================================*/
17 #include "clitkTimer.h"
19 //====================================================================
20 /// Constructs the class
21 clitk::Timer::Timer() {
24 QueryPerformanceFrequency((LARGE_INTEGER*)&mFrequency);
27 //====================================================================
29 //====================================================================
30 void clitk::Timer::Start() {
32 getrusage(RUSAGE_SELF, &mBegin);
34 QueryPerformanceCounter((LARGE_INTEGER*)&mBegin);
38 //====================================================================
40 //====================================================================
41 void clitk::Timer::Stop(bool accumulate) {
43 getrusage(RUSAGE_SELF, &mEnd);
45 mElapsed += (mEnd.ru_utime.tv_usec - mBegin.ru_utime.tv_usec)+
46 (mEnd.ru_utime.tv_sec - mBegin.ru_utime.tv_sec)*1000000;
49 QueryPerformanceCounter((LARGE_INTEGER*)&mEnd);
51 mElapsed += ((mEnd-mBegin)*1000000)/(long double)mFrequency;
58 //====================================================================
60 //====================================================================
61 void clitk::Timer::Print(std::ostream & os) const {
62 if (mNumberOfCall != 1) {
63 os << "Timer # = " << mNumberOfCall << std::endl;
64 os << "Timer total = " << mElapsed << " usec \t" << mElapsed/1000000.0 << " sec." << mElapsed/1000000.0/60 << " min."
65 << mElapsed/1000000.0/60/60 << " hours." << std::endl;
67 long double tus = mElapsed/mNumberOfCall;
68 long double ts = tus/1000000.0;
69 long double tm = ts/60.0;
70 long double th = tm/60.0;
71 os << "Timer = " << tus << " usec\t" << ts << " sec.\t" << tm << " min.\t" << th << " hours." << std::endl;
72 // os << "\tmBegin.ru_utime.tv_sec = " << mBegin.ru_utime.tv_sec << std::endl;
73 // os << "\tmEnd.ru_utime.tv_sec = " << mEnd.ru_utime.tv_sec << std::endl;
74 // os << "\tmBegin.ru_utime.tv_usec = " << mBegin.ru_utime.tv_usec << std::endl;
75 // os << "\tmEnd.ru_utime.tv_usec = " << mEnd.ru_utime.tv_usec << std::endl;
77 //====================================================================
79 //====================================================================
80 void clitk::Timer::Print(std::string text, std::ostream & os) const {
84 //====================================================================
86 //====================================================================
87 void clitk::Timer::Reset() {
91 //====================================================================
94 #endif /* end #define CLITKTIMER_CXX */