33#ifndef DART_COMMON_STOPWATCH_HPP_
34#define DART_COMMON_STOPWATCH_HPP_
44 typename ClockType = std::chrono::high_resolution_clock>
73 [[nodiscard]]
double elapsedS()
const;
85 void print(std::ostream& os = std::cout)
const;
88 template <
typename T,
typename U>
99 [[nodiscard]] UnitType
duration()
const;
120double toc(
bool print =
false);
123double tocS(
bool print =
false);
126double tocMS(
bool print =
false);
129double tocUS(
bool print =
false);
132double tocNS(
bool print =
false);
Simple stopwatch implementation.
Definition Stopwatch.hpp:46
bool mPaused
Whether the stopwatch is paused.
Definition Stopwatch.hpp:108
Stopwatch & operator=(Stopwatch &&)=delete
double elapsedMS() const
Returns the elapsed time in milliseconds.
Definition Stopwatch-impl.hpp:140
double elapsedS() const
Returns the elapsed time in seconds.
Definition Stopwatch-impl.hpp:118
void stop()
Stops the stopwatch.
Definition Stopwatch-impl.hpp:97
void start()
Starts the stopwatch.
Definition Stopwatch-impl.hpp:84
void reset()
Resets the stopwatch.
Definition Stopwatch-impl.hpp:110
bool isStarted() const
Returns whether the stopwatch is started.
Definition Stopwatch-impl.hpp:77
ClockType::time_point mStart
The start time.
Definition Stopwatch.hpp:102
void print(std::ostream &os=std::cout) const
Prints state of the stopwatch.
Definition Stopwatch-impl.hpp:222
Stopwatch(const Stopwatch &)=delete
UnitType mElapsed
The elapsed time.
Definition Stopwatch.hpp:105
double elapsedNS() const
Returns the elapsed time in nanoseconds.
Definition Stopwatch-impl.hpp:186
~Stopwatch()
Destructor.
Definition Stopwatch-impl.hpp:70
friend std::ostream & operator<<(std::ostream &os, const Stopwatch< T, U > &sw)
Prints state of the stopwatch.
Stopwatch(Stopwatch &&)=delete
double elapsedUS() const
Returns the elapsed time in microseconds.
Definition Stopwatch-impl.hpp:163
UnitType duration() const
Returns the duration.
Definition Stopwatch-impl.hpp:208
Stopwatch & operator=(const Stopwatch &)=delete
double tocUS(bool print)
Returns the elapsed time in microseconds since the last tic() call.
Definition Stopwatch.cpp:84
double tocS(bool print)
Returns the elapsed time in seconds since the last tic() call.
Definition Stopwatch.cpp:54
double tocMS(bool print)
Returns the elapsed time in milliseconds since the last tic() call.
Definition Stopwatch.cpp:69
double tocNS(bool print)
Returns the elapsed time in nanoseconds since the last tic() call.
Definition Stopwatch.cpp:99
double toc(bool print)
Returns the elapsed time in seconds since the last tic() call.
Definition Stopwatch.cpp:48
void tic()
MATLAB like timer.
Definition Stopwatch.cpp:42