#include <stopwatch.h>
template<typename Clock = std::chrono::steady_clock>
StopWatch_ class
A stop watch with configurable clock.
Contents
A stop watch measures the time since you last called Start(), or since its construction. Use its ElapsedXXX() methods to get the elapsed time in the corresponding time interval (i.e. precision), e.g. ElapsedSeconds().
Duration measurements should use a monotonic clock. Thus, we explicitly default to steady_clock (since high_resolution_clock is not guaranteed to be steady).
Public types
- using clock_type = Clock
- Clock type used by this stop watch.
Constructors, destructors, conversion operators
- StopWatch_()
- Constructor starts the stop watch.
-
StopWatch_(const StopWatch_
& other) - Copy-constructor copies the other's start time point.
- ~StopWatch_() defaulted
-
StopWatch_(StopWatch_
&& other) defaulted noexcept
Public functions
-
auto operator=(const StopWatch_
& other) -> StopWatch_ & defaulted -
auto operator=(StopWatch_
&& other) -> StopWatch_ & defaulted noexcept - void Start()
- Starts or restarts the stop watch.
-
template<typename Ratio>auto ElapsedAs() const -> double
- Returns the elapsed time as ticks of the given time interval.
- auto ElapsedSeconds() const -> double
- Returns the elapsed time in seconds.
- auto ElapsedMilliseconds() const -> double
- Returns the elapsed time in milliseconds.
- auto ElapsedMicroseconds() const -> double
- Returns the elapsed time in microseconds.
- auto ElapsedNanoseconds() const -> double
- Returns the elapsed time in nanoseconds.
- auto YearsUntilOverflow() const -> double
- Returns the number of years before this stop watch will overflow.
- auto IsSteady() const -> bool
- Returns true if the used clock is steady (monotonic).
- auto ClockName() const -> std::string
- Returns a readable clock typeid, for example
"std::chrono::steady_clock".
Function documentation
template<typename Clock>
template<typename Ratio>
double werkzeugkiste:: timing:: StopWatch_<Clock>:: ElapsedAs() const
Returns the elapsed time as ticks of the given time interval.
The time interval is a rational fraction, i.e. std::ratio, which represents the time in seconds from one tick to the next, i.e. similar to the Period template parameter in std::chrono::duration.