A basic stopwatch for measuring time. More...
Public Types | |
using | time_point = typename Clock::time_point |
using | duration = typename Clock::duration |
using | rep = typename Clock::rep |
using | period = typename Clock::period |
Public Member Functions | |
void | start () |
Starts the stopwatch. | |
void | stop () |
Stops the stopwatch. | |
void | reset () |
Resets the stopwatch. More... | |
void | restart () |
Restarts the stopwatch. More... | |
template<typename Duration = std::chrono::milliseconds> | |
rep | elapsed () |
Returns the elapsed time. More... | |
bool | is_running () const |
Checks if the stopwatch is running. | |
Clock | The internal clock to use to calculate time |
basic_stopwatch is a class that defines the most basic stopwatch representation. It's underlying clock can be configured through its template parameter to give you the most flexibility desired.
For convenience, a typedef named stopwatch
is provided that defaults to std::chrono::high_resolution_clock
as the internal clock used.
Example usage:
Possible Output:
1159 1
Definition at line 30 of file stopwatch.hpp.
|
inline |
The elapsed time is considered the time since the stopwatch was started via the start member function. Consecutive calls to elapsed would not stop the watch and would simply return the elapsed time since the starting point.
Duration | The duration to cast the elapsed time to. Defaults to std::chrono::milliseconds . |
Definition at line 107 of file stopwatch.hpp.
|
inline |
Resets the stopwatch and pauses it. Meaning that it sets the elapsed time to zero and the post-condition of is_running is false.
Definition at line 71 of file stopwatch.hpp.
|
inline |
Restarts the stopwatch, meaning that it sets the elapsed time to zero, and starts the stopwatch again. This is equivalent to doing the following:
Definition at line 89 of file stopwatch.hpp.