17 #ifndef CARTOGRAPHER_COMMON_RATE_TIMER_H_ 18 #define CARTOGRAPHER_COMMON_RATE_TIMER_H_ 36 template <
typename ClockType = std::chrono::steady_clock>
53 return static_cast<double>(
events_.size() - 1) /
65 std::chrono::duration_cast<std::chrono::duration<double>>(
85 std::ostringstream out;
86 out << std::fixed << std::setprecision(2) <<
ComputeRate() <<
" Hz " 102 std::vector<double> result;
103 result.reserve(count);
104 for (
size_t i = 0; i !=
count; ++i) {
114 const double sum = std::accumulate(deltas.begin(), deltas.end(), 0.);
115 const double mean = sum / deltas.size();
117 double squared_sum = 0.;
118 for (
const double x : deltas) {
121 const double sigma = std::sqrt(squared_sum / (deltas.size() - 1));
123 std::ostringstream out;
124 out << std::scientific << std::setprecision(2) << mean <<
" s +/- " << sigma
136 #endif // CARTOGRAPHER_COMMON_RATE_TIMER_H_
const common::Duration window_duration_
std::vector< double > ComputeDeltasInSeconds() const
double ComputeRate() const
string DeltasDebugString() const
std::deque< Event > events_
UniversalTimeScaleClock::time_point Time
double ComputeWallTimeRateRatio() const
RateTimer & operator=(const RateTimer &)=delete
UniversalTimeScaleClock::duration Duration
string DebugString() const
RateTimer(const common::Duration window_duration)
double ToSeconds(const Duration duration)
ClockType::time_point wall_time
void Pulse(common::Time time)