32 template<
typename T = std::chrono::system_clock>
38 Stopwatch(std::string name =
"stopwatch",
bool running =
false)
81 typename T::duration
get()
const {
92 using namespace std::chrono;
95 typedef typename TClock::period TPeriod;
96 if (ratio_less_equal<TPeriod, micro>::value) {
97 microseconds d = duration_cast<microseconds>(
get());
99 }
else if (ratio_less_equal<TPeriod, milli>::value) {
100 milliseconds d = duration_cast<milliseconds>(
get());
103 seconds d = duration_cast<seconds>(
get());
120 std::ostream& operator<<(std::ostream& oss, Stopwatch<T>
const& stopwatch) {
121 return (oss << stopwatch.toString());
Stopwatch & reset()
Resets stopwatch i.e. stopwatch is stopped and time accumulator is cleared.
Time Dependent Person DataType.
bool isRunning() const
Reports whether stopwatch has been started.
Provides a stopwatch interface to time: it accumulates time between start/stop pairs.
Stopwatch & stop()
Stops the stopwatch if it was running.
Stopwatch(std::string name="stopwatch", bool running=false)
Constructor initializes stopwatch.
Utilities to tag clocks and reformat clock readout to string.
std::string getName() const
Return name of this stopwatch.
Stopwatch & start()
Starts stopwatch if it was stopped.
T::duration m_accumulated
T::time_point m_last_start
std::string toString() const
Returns string representation of readout.
static std::string toColonString(std::chrono::seconds d)
Produce string in hh:mm:ss format.