68 auto end_time = std::chrono::steady_clock::now();
69 return std::chrono::duration<double, std::ratio<1, 1000>>(end_time -
start_time_).count();
87 std::chrono::time_point<std::chrono::steady_clock>
start_time_ = std::chrono::steady_clock::now();
116 std::cerr << title_ <<
" took " << val <<
"ms.\n";
142 : window_size_ (window_size)
144 stop_watch_.
reset ();
151 if (event_time_queue_.size () > window_size_)
152 event_time_queue_.pop ();
159 if (event_time_queue_.size () < 2)
161 return ((event_time_queue_.size () - 1) /
162 (event_time_queue_.back () - event_time_queue_.front ()));
168 stop_watch_.
reset ();
169 event_time_queue_ = std::queue<double> ();
175 std::queue<double> event_time_queue_;
176 const std::size_t window_size_;
180 #ifndef MEASURE_FUNCTION_TIME
181 #define MEASURE_FUNCTION_TIME \
182 ScopeTime scopeTime(__func__)
188 return std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count();
193 #define DO_EVERY_TS(secs, currentTime, code) \
195 static double s_lastDone_ = 0.0; \
196 double s_now_ = (currentTime); \
197 if (s_lastDone_ > s_now_) \
198 s_lastDone_ = s_now_; \
199 if ((s_now_ - s_lastDone_) > (secs)) { \
201 s_lastDone_ = s_now_; \
209 #define DO_EVERY(secs, code) \
210 DO_EVERY_TS(secs, pcl::getTime(), code)
A helper class to measure frequency of a certain event.
void reset()
Reset frequency computation.
double getFrequency() const
Retrieve the estimated frequency.
EventFrequency(std::size_t window_size=30)
Constructor.
void event()
Notifies the class that the event occurred.
Class to measure the time spent in a scope.
ScopeTime(const std::string &title="")
double getTime() const
Retrieve the time in milliseconds spent since the last call to reset().
double getTimeSeconds() const
Retrieve the time in seconds spent since the last call to reset().
void reset()
Reset the stopwatch to 0.
std::chrono::time_point< std::chrono::steady_clock > start_time_
StopWatch()=default
Constructor.