00001
00002
00003
00004 #ifndef AITOOLS_INVERTEDINDEX_TIMER_HPP
00005 #define AITOOLS_INVERTEDINDEX_TIMER_HPP
00006
00007 #include <boost/timer.hpp>
00008
00009 #ifdef _WIN32 // this is also defined on Win64 platforms by default
00010
00011 namespace aitools {
00012 namespace invertedindex {
00013
00014 typedef boost::timer Timer;
00015
00016 }
00017 }
00018
00019 #else
00020 #include <sys/time.h>
00021
00022 namespace aitools {
00023 namespace invertedindex {
00024
00036 class Timer : public boost::timer {
00037
00038 private:
00039
00040 static const double divisor = 1000000;
00041
00042 public:
00043
00044 Timer()
00045 {
00046 ::gettimeofday(&time_, NULL);
00047 }
00048
00049 public:
00050
00051 void restart()
00052 {
00053 ::gettimeofday(&time_, NULL);
00054 }
00055
00056 double elapsed() const
00057 {
00058 ::timeval now;
00059 ::gettimeofday(&now, NULL);
00060 return (now.tv_sec - time_.tv_sec) +
00061 (now.tv_usec - time_.tv_usec) / divisor;
00062 }
00063
00064 double elapsed_max() const
00065 {
00066 return double((std::numeric_limits<__time_t>::max)()) - time_.tv_sec;
00067 }
00068
00069 double elapsed_min() const
00070 {
00071 return double((std::numeric_limits<__suseconds_t>::min)());
00072 }
00073
00074 private:
00075
00076 ::timeval time_;
00077
00078 };
00079
00080 }
00081 }
00082
00083 #endif // Not defined _WIN32
00084 #endif // AITOOLS_INVERTEDINDEX_TIMER_HPP