Provides time interval measurements. More...
#include <StopWatch.h>
Classes | |
struct | makeDurationTrait |
Trait whose type member is a std::chrono::duration type. More... | |
struct | makeDurationTrait< std::chrono::duration< Rep, Duration > > |
struct | makeDurationTrait< std::ratio< Num, Den > > |
Public Types | |
using | Clock_t = Clock |
type of clock used to extract current time More... | |
using | DefaultUnit_t = DefaultUnit |
default unit for time report More... | |
using | ElapsedTime_t = typename DefaultUnit_t::rep |
Type representing the reported time. More... | |
using | Clock_t = Clock |
type of clock used to extract current time More... | |
using | DefaultUnit_t = DefaultUnit |
default unit for time report More... | |
using | ElapsedTime_t = typename DefaultUnit_t::rep |
Type representing the reported time. More... | |
Public Member Functions | |
StopWatch (bool start=true) | |
Initializes and starts the timer. More... | |
template<typename Unit > | |
StopWatch (Unit prev, bool start=true) | |
Initializes and starts the timer. More... | |
StopWatch (bool start=true) | |
Initializes and starts the timer. More... | |
template<typename Unit > | |
StopWatch (Unit prev, bool start=true) | |
Initializes and starts the timer. More... | |
Watch control | |
void | restart () |
Restarts the watch; previous time is forgotten. More... | |
void | resume () |
Resumes the run of the watch; previous time is preserved. More... | |
void | stop () |
Pauses the watch. More... | |
template<typename Unit = DefaultUnit_t> | |
void | setPrevious (Unit dur) |
Changes the amount of time accumulated before this run. More... | |
void | restart () |
Restarts the watch; previous time is forgotten. More... | |
void | resume () |
Resumes the run of the watch; previous time is preserved. More... | |
void | stop () |
Pauses the watch. More... | |
template<typename Unit = DefaultUnit_t> | |
void | setPrevious (Unit dur) |
Changes the amount of time accumulated before this run. More... | |
Query | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | elapsed () const |
Returns the total time spent running since the last restart. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | partial () const |
Returns the time spent running since the last resume. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | previous () const |
Returns the time accumulated before the current run. More... | |
bool | running () const |
Returns whether the watch is tracking time right now. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | elapsed () const |
Returns the total time spent running since the last restart. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | partial () const |
Returns the time spent running since the last resume. More... | |
template<typename Unit = DefaultUnit_t> | |
ElapsedTime_t | previous () const |
Returns the time accumulated before the current run. More... | |
bool | running () const |
Returns whether the watch is tracking time right now. More... | |
Protected Types | |
using | TimePoint_t = decltype(Clock_t::now()) |
type to store start time More... | |
template<typename Unit > | |
using | makeDuration_t = typename makeDurationTrait< Unit >::type |
Type of std::chrono::duration type constructed from makeDurationTrait. More... | |
using | TimePoint_t = decltype(Clock_t::now()) |
type to store start time More... | |
template<typename Unit > | |
using | makeDuration_t = typename makeDurationTrait< Unit >::type |
Type of std::chrono::duration type constructed from makeDurationTrait. More... | |
Protected Member Functions | |
DefaultUnit_t | partialDur () const |
Returns partial time as a duration. More... | |
DefaultUnit_t | partialDur () const |
Returns partial time as a duration. More... | |
Static Protected Member Functions | |
static TimePoint_t | now () |
Returns the current time point from our clock. More... | |
template<typename Unit , typename From > | |
static auto | durationTo (From const &dur) |
Convert a duration into a unit (may be a ratio or a duration) More... | |
static TimePoint_t | now () |
Returns the current time point from our clock. More... | |
template<typename Unit , typename From > | |
static auto | durationTo (From const &dur) |
Convert a duration into a unit (may be a ratio or a duration) More... | |
Protected Attributes | |
TimePoint_t | lastStart |
time of the last start More... | |
DefaultUnit_t | previousTime |
time accumulated from previous runs More... | |
bool | isRunning |
whether we are measuring time now More... | |
Provides time interval measurements.
DefaultUnit | unit reported by default (seconds, floating point) |
Clock | type of clock object used (default: high_resolution_clock) |
The stopwatch keeps track of the clock and can return the time elapsed from a previous time mark. Example of use:
The time from all methods returning a value are in the DefaultUnit_t unit.
On DefaultUnit
type:
On Clock
type:
now()
static function returning std::chrono::time_point
Definition at line 79 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::Clock_t = Clock |
type of clock used to extract current time
Definition at line 84 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::Clock_t = Clock |
type of clock used to extract current time
Definition at line 84 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::DefaultUnit_t = DefaultUnit |
default unit for time report
Definition at line 85 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::DefaultUnit_t = DefaultUnit |
default unit for time report
Definition at line 85 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t = typename DefaultUnit_t::rep |
Type representing the reported time.
Definition at line 88 of file StopWatch.h.
using testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t = typename DefaultUnit_t::rep |
Type representing the reported time.
Definition at line 88 of file StopWatch.h.
|
protected |
Type of std::chrono::duration type constructed from makeDurationTrait.
Definition at line 164 of file StopWatch.h.
|
protected |
Type of std::chrono::duration type constructed from makeDurationTrait.
Definition at line 164 of file StopWatch.h.
|
protected |
type to store start time
Definition at line 145 of file StopWatch.h.
|
protected |
type to store start time
Definition at line 145 of file StopWatch.h.
testing::StopWatch< DefaultUnit, Clock >::StopWatch | ( | bool | start = true | ) |
Initializes and starts the timer.
start | whether to start immediately (default: true) |
Definition at line 199 of file StopWatch.h.
testing::StopWatch< DefaultUnit, Clock >::StopWatch | ( | Unit | prev, |
bool | start = true |
||
) |
Initializes and starts the timer.
prev | time already accumulated on start |
start | whether to start immediately (default: true) |
Definition at line 209 of file StopWatch.h.
testing::StopWatch< DefaultUnit, Clock >::StopWatch | ( | bool | start = true | ) |
Initializes and starts the timer.
start | whether to start immediately (default: true) |
testing::StopWatch< DefaultUnit, Clock >::StopWatch | ( | Unit | prev, |
bool | start = true |
||
) |
Initializes and starts the timer.
prev | time already accumulated on start |
start | whether to start immediately (default: true) |
|
staticprotected |
Convert a duration into a unit (may be a ratio or a duration)
Definition at line 326 of file StopWatch.h.
|
staticprotected |
Convert a duration into a unit (may be a ratio or a duration)
ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::elapsed | ( | ) | const |
Returns the total time spent running since the last restart.
testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::elapsed | ( | ) | const |
Returns the total time spent running since the last restart.
Definition at line 254 of file StopWatch.h.
|
staticprotected |
Returns the current time point from our clock.
|
staticprotected |
ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::partial | ( | ) | const |
Returns the time spent running since the last resume.
testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::partial | ( | ) | const |
Returns the time spent running since the last resume.
Definition at line 264 of file StopWatch.h.
|
protected |
Returns partial time as a duration.
Definition at line 294 of file StopWatch.h.
|
protected |
Returns partial time as a duration.
ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::previous | ( | ) | const |
Returns the time accumulated before the current run.
testing::StopWatch< DefaultUnit, Clock >::ElapsedTime_t testing::StopWatch< DefaultUnit, Clock >::previous | ( | ) | const |
Returns the time accumulated before the current run.
Definition at line 273 of file StopWatch.h.
void testing::StopWatch< DefaultUnit, Clock >::restart | ( | ) |
Restarts the watch; previous time is forgotten.
Definition at line 218 of file StopWatch.h.
void testing::StopWatch< DefaultUnit, Clock >::restart | ( | ) |
Restarts the watch; previous time is forgotten.
void testing::StopWatch< DefaultUnit, Clock >::resume | ( | ) |
Resumes the run of the watch; previous time is preserved.
void testing::StopWatch< DefaultUnit, Clock >::resume | ( | ) |
Resumes the run of the watch; previous time is preserved.
Definition at line 227 of file StopWatch.h.
bool testing::StopWatch< DefaultUnit, Clock >::running | ( | ) | const |
Returns whether the watch is tracking time right now.
Definition at line 280 of file StopWatch.h.
bool testing::StopWatch< DefaultUnit, Clock >::running | ( | ) | const |
Returns whether the watch is tracking time right now.
void testing::StopWatch< DefaultUnit, Clock >::setPrevious | ( | Unit | dur | ) |
Changes the amount of time accumulated before this run.
void testing::StopWatch< DefaultUnit, Clock >::setPrevious | ( | Unit | dur | ) |
Changes the amount of time accumulated before this run.
Definition at line 245 of file StopWatch.h.
void testing::StopWatch< DefaultUnit, Clock >::stop | ( | ) |
Pauses the watch.
Definition at line 236 of file StopWatch.h.
void testing::StopWatch< DefaultUnit, Clock >::stop | ( | ) |
Pauses the watch.
|
protected |
whether we are measuring time now
Definition at line 149 of file StopWatch.h.
|
protected |
time of the last start
Definition at line 147 of file StopWatch.h.
|
protected |
time accumulated from previous runs
Definition at line 148 of file StopWatch.h.