18 #ifndef HPP_UTIL_TIMER_HH 19 # define HPP_UTIL_TIMER_HH 21 # include "boost/date_time/posix_time/posix_time_types.hpp" 23 # ifdef HPP_ENABLE_BENCHMARK 24 # include <boost/date_time/posix_time/posix_time.hpp> 25 # endif // HPP_ENABLE_BENCHMARK 27 # include <hpp/util/config.hh> 37 typedef boost::posix_time::ptime
ptime;
41 explicit Timer (
bool autoStart =
false);
46 const ptime& start ();
48 time_duration duration ()
const;
50 const ptime& getStart ()
const;
51 const ptime& getStop ()
const;
53 std::ostream& print (std::ostream&)
const;
59 # ifdef HPP_ENABLE_BENCHMARK 61 # define hppStartBenchmark(ID) \ 62 hppDout (benchmark, #ID << ": start"); \ 63 ::hpp::debug::Timer _##ID##_timer_ (true) 65 # define hppStopBenchmark(ID) \ 67 _##ID##_timer_.stop (); \ 68 hppDout (benchmark, #ID << ": stop"); \ 71 # define hppDisplayBenchmark(ID) \ 72 hppDout (benchmark, #ID << ": "<< _##ID##_timer_.duration ()); 74 # define hppBenchmark(data) \ 76 using namespace hpp; \ 77 using namespace ::hpp::debug; \ 78 std::stringstream __ss; \ 79 __ss << data << iendl; \ 80 logging.benchmark.write (__FILE__, __LINE__, __PRETTY_FUNCTION__, \ 85 # define hppStartBenchmark(ID) 86 # define hppStopBenchmark(ID) 87 # define hppDisplayBenchmark(ID) 88 # define hppBenchmark(data) 89 # endif // HPP_ENABLE_BENCHMARK 102 typedef boost::posix_time::ptime
ptime;
108 time_duration stop ();
109 time_duration last ();
112 time_duration min ()
const;
113 time_duration max ()
const;
114 time_duration mean ()
const;
115 time_duration totalTime ()
const;
117 std::ostream& print (std::ostream& os)
const;
122 time_duration t_, last_, min_, max_;
128 # ifdef HPP_ENABLE_BENCHMARK 134 # define HPP_DEFINE_TIMECOUNTER(name) \ 135 ::hpp::debug::TimeCounter _##name##_timecounter_ (#name) 136 # define HPP_SCOPE_TIMECOUNTER(name) \ 138 ::hpp::debug::TimeCounter::Scope _##name##_scopetimecounter_ \ 139 (_##name##_timecounter_) 140 # define HPP_START_TIMECOUNTER(name) \ 142 _##name##_timecounter_.start () 143 # define HPP_STOP_TIMECOUNTER(name) \ 145 _##name##_timecounter_.stop() 146 # define HPP_DISPLAY_LAST_TIMECOUNTER(name) \ 149 using namespace hpp; \ 150 using namespace ::hpp::debug; \ 151 std::stringstream __ss; \ 152 __ss << #name << " last: " \ 153 << _##name##_timecounter_.last() << iendl; \ 154 logging.benchmark.write (__FILE__, __LINE__, \ 155 __PRETTY_FUNCTION__, __ss); \ 157 # define HPP_DISPLAY_TIMECOUNTER(name) \ 160 using namespace hpp; \ 161 using namespace ::hpp::debug; \ 162 std::stringstream __ss; \ 163 __ss << _##name##_timecounter_ << iendl; \ 164 logging.benchmark.write (__FILE__, __LINE__, \ 165 __PRETTY_FUNCTION__, __ss); \ 167 # define HPP_RESET_TIMECOUNTER(name) \ 169 _##name##_timecounter_.reset(); 170 # define HPP_STREAM_TIMECOUNTER(os, name) \ 172 os << _##name##_timecounter_ 173 # else // HPP_ENABLE_BENCHMARK 175 # define HPP_DEFINE_TIMECOUNTER(name) \ 176 struct _##name##_EndWithSemiColon_{} 177 # define HPP_SCOPE_TIMECOUNTER(name) 178 # define HPP_START_TIMECOUNTER(name) 179 # define HPP_STOP_TIMECOUNTER(name) 180 # define HPP_DISPLAY_LAST_TIMECOUNTER(name) 181 # define HPP_DISPLAY_TIMECOUNTER(name) 182 # define HPP_RESET_TIMECOUNTER(name) 183 # define HPP_STREAM_TIMECOUNTER(os, name) \ 185 # endif // HPP_ENABLE_BENCHMARK 187 # define HPP_STOP_AND_DISPLAY_TIMECOUNTER(name) \ 188 HPP_STOP_TIMECOUNTER(name); \ 189 HPP_DISPLAY_TIMECOUNTER(name) 194 #endif // HPP_UTIL_TIMER_HH boost::posix_time::time_duration time_duration
Definition: timer.hh:38
~Scope()
Definition: timer.hh:97
Definition: assertion.hh:24
void start()
Definition: timer.cc:101
boost::posix_time::time_period time_period
Definition: timer.hh:39
std::ostream & operator<<(std::ostream &os, const TimeCounter &tc)
Definition: timer.cc:160
Scope(TimeCounter &t)
Definition: timer.hh:96
boost::posix_time::time_duration time_duration
Definition: timer.hh:103
boost::posix_time::ptime ptime
Definition: timer.hh:37
TimeCounter & tc
Definition: timer.hh:99
boost::posix_time::ptime ptime
Definition: timer.hh:102
Computation of min, max and mean time from a set of measurements.
Definition: timer.hh:92