1 #ifndef UTIL_CLOCK_MAN_STOPWATCH_H_INCLUDED
2 #define UTIL_CLOCK_MAN_STOPWATCH_H_INCLUDED
38 template<
typename T = std::chrono::system_clock>
45 Stopwatch(std::string name =
"stopwatch",
bool running =
false)
46 : m_accumulated(T::duration::zero()), m_name(name), m_running(running)
49 m_last_start = T::now();
58 m_last_start = T::now();
67 m_accumulated += (T::now() - m_last_start);
76 m_accumulated = T::duration::zero();
94 typename T::duration
Get()
const
96 auto fTemp = m_accumulated;
98 fTemp += (T::now() - m_last_start);
110 typedef typename TClock::period TPeriod;
111 if (ratio_less_equal<TPeriod, micro>::value) {
112 microseconds d = duration_cast < microseconds > (
Get());
114 }
else if (ratio_less_equal<TPeriod, milli>::value) {
115 milliseconds d = duration_cast < milliseconds > (
Get());
118 seconds d = duration_cast < seconds > (
Get());
125 typename T::duration m_accumulated;
126 typename T::time_point m_last_start;
136 operator<<(std::ostream& oss, Stopwatch<T>
const& stopwatch) {
137 return (oss << stopwatch.ToString());
143 #endif // end of include guard
bool IsRunning() const
Reports whether stopwatch has been started.
std::string GetName() const
Return name of this stopwatch.
Interface for TimeKeeper::Utils.
static std::string ToColonString(std::chrono::seconds d)
Procude string in hh:mm:ss format.
Namespace for the core simulator.
Stopwatch & Stop()
Stops the stopwatch if it was running.
Stopwatch(std::string name="stopwatch", bool running=false)
Constructor initializes stopwatch.
T::duration Get() const
Returns the accumulated value without altering the stopwatch state.
std::string ToString() const
Returns string representation of readout.
Provides a stopwatch interface to time: it accumulates time between start/stop pairs.
Stopwatch & Reset()
Resets stopwatch i.e. stopwatch is stopped and time accumulator is cleared.
Stopwatch & Start()
Starts stopwatch if it was stopped.