2 #ifndef SYDEVS_TIMER_H_
3 #define SYDEVS_TIMER_H_
10 using clock = std::chrono::steady_clock;
66 , cumulative_dt_(cumulative_dt)
80 return cumulative_dt_;
87 throw std::runtime_error(
"Attempt to start timer that has already been started");
89 start_clk_t_ = clock::now();
95 auto stop_clk_t = clock::now();
97 throw std::runtime_error(
"Attempt to stop timer that has not been started");
99 auto microsecond_count = std::chrono::duration_cast<std::chrono::microseconds>(stop_clk_t - start_clk_t_).count();
101 cumulative_dt_ += interval_dt;
bool timing() const
Returns true if the timer has been started but not yet stopped.
Definition: timer.h:72
duration cumulative_duration() const
Returns the cumulative duration of measured time.
Definition: timer.h:78
duration stop()
Stops the timer and returns the measured interval of wallclock time.
Definition: timer.h:93
constexpr const quantity fixed_at(scale precision) const
Returns a new quantity value with the length precision changed and fixed.
Definition: quantity.h:610
timer()
Constructs a timer that has not yet accumuated any interval measurements.
Definition: timer.h:56
A class for measuring and accumulating intervals of wallclock time.
Definition: timer.h:24
constexpr scale micro
Definition: scale.h:161
std::chrono::time_point< clock > clock_time
Definition: timer.h:11
timer & operator=(const timer &)=delete
Copy assignment.
void start()
Starts the timer.
Definition: timer.h:84
quantity< seconds > duration
Definition: quantity.h:1006
~timer()=default
Destructor.
std::chrono::steady_clock clock
Definition: timer.h:10