OBOE 0.1
|
00001 // Copyright (c) 2004-2007 University of Geneva, HEC, Logilab 00002 // 00003 // OBOE is published under the Common Public License. 00004 // 00005 // Authors : 00006 // The OBOE team 00007 // 00008 00009 #ifndef TIMER_H 00010 #define TIMER_H 00011 00012 #include <config.h> 00013 #include <iostream> 00014 #if (defined(LINUX)) 00015 #include <sys/times.h> 00016 #include <unistd.h> 00017 #endif 00018 00019 #if (defined(WIN32)) 00020 #include <time.h> 00021 //#include <unistd.h> 00022 #endif 00023 00029 namespace Accpm { 00030 00031 class Timer { 00032 00033 #if (defined(LINUX)) 00034 private: 00035 struct tms _startTime; 00036 clock_t _startClock; 00037 struct tms _endTime; 00038 clock_t _endClock; 00039 const double _clockTicks; 00040 00041 public: 00042 Timer() : _clockTicks(sysconf(_SC_CLK_TCK)) {} 00043 inline void start() { _startClock = times(&_startTime); } 00044 inline void stop() { _endClock = times(&_endTime); } 00045 double getRealTime() const { return (_endClock - _startClock)/_clockTicks;} 00046 double getCpuTime() const { return (_endTime.tms_utime - _startTime.tms_utime 00047 + _endTime.tms_stime - _startTime.tms_stime)/_clockTicks; } 00048 double getSysTime() const { return (_endTime.tms_stime - _startTime.tms_stime)/_clockTicks; } 00049 #endif 00050 00051 #if (defined(WIN32)) 00052 private: 00053 time_t _startTime; 00054 clock_t _startClock; 00055 time_t _endTime; 00056 clock_t _endClock; 00057 const double _clockTicks; 00058 00059 public: 00060 Timer() : _clockTicks(CLK_TCK) {} 00061 inline void start() { _startClock = time(&_startTime); _startClock = clock_t();} 00062 inline void stop() { _endClock = time(&_endTime); _endClock = clock_t();} 00063 double getRealTime() const { return _endTime - _startTime;} 00064 //double getCpuTime() const { return (_endClock - _startClock)/_clockTicks; } 00065 // Dont know how to get CPU time on windows 00066 double getCpuTime() const { return getRealTime(); } 00067 double getSysTime() const { std::cout << "Function Timer::getSysTime() not supported\n"; return 0; } 00068 #endif 00069 00070 }; 00071 00072 00073 } 00074 #endif