34 template <
typename T = std::chrono::steady_clock>
41 explicit Stopwatch(std::string name =
"stopwatch",
bool running =
false)
84 typename T::duration
Get()
const 100 typedef typename TClock::period TPeriod;
101 if (ratio_less_equal<TPeriod, micro>::value) {
102 microseconds d = duration_cast<microseconds>(
Get());
104 }
else if (ratio_less_equal<TPeriod, milli>::value) {
105 milliseconds d = duration_cast<milliseconds>(
Get());
108 seconds d = duration_cast<seconds>(
Get());
124 template <
typename T>
125 std::ostream& operator<<(std::ostream& oss, Stopwatch<T>
const& stopwatch)
127 return (oss << stopwatch.ToString());
T::time_point m_last_start
Utilities to tag clocks and reformat clock readout to string.
Stopwatch & Start()
Starts stopwatch if it was stopped.
std::string GetName() const
Return name of this stopwatch.
Stopwatch & Stop()
Stops the stopwatch if it was running.
Provides a stopwatch interface to time: it accumulates time between start/stop pairs.
bool IsRunning() const
Reports whether stopwatch has been started.
std::string ToString() const
Returns string representation of readout.
static std::string ToColonString(std::chrono::minutes d)
Produce string in hh:mm:ss format.
Stopwatch & Reset()
Resets stopwatch i.e. stopwatch is stopped and time accumulator is cleared.
T::duration m_accumulated
Stopwatch(std::string name="stopwatch", bool running=false)
Constructor initializes stopwatch.
T::duration Get() const
Returns the accumulated value without altering the stopwatch state.
Namespace for the simulator and related classes.