46 #include <ilqgames/utils/loop_timer.h> 47 #include <ilqgames/utils/types.h> 49 #include <glog/logging.h> 55 void LoopTimer::Tic() { start_ = std::chrono::high_resolution_clock::now(); }
57 Time LoopTimer::Toc() {
59 const Time elapsed = (std::chrono::duration<Time>(
60 std::chrono::high_resolution_clock::now() - start_))
64 loop_times_.push_back(elapsed);
65 total_time_ += elapsed;
67 if (loop_times_.size() > max_samples_) {
68 total_time_ -= loop_times_.front();
69 loop_times_.pop_front();
75 Time LoopTimer::RuntimeUpperBound(
float num_stddevs, Time initial_guess)
const {
77 if (loop_times_.size() < 2)
return initial_guess;
80 const Time mean = total_time_ /
static_cast<Time
>(loop_times_.size());
82 for (
const Time entry : loop_times_) {
83 const Time diff = entry - mean;
84 variance += diff * diff;
88 variance /=
static_cast<Time
>(loop_times_.size() - 1);
91 return mean + num_stddevs * std::sqrt(variance);