Reports time elapsed at the end of an object scope. More...
#include <optimer.hpp>
Public Types | |
using | clock = ClockType |
using | resolution = ResolutionType |
using | point = typename clock::time_point |
using | interval = typename clock::duration |
using | report_callback = std::function< void(const optimer &)> |
Public Member Functions | |
optimer (report_callback f=report_callback{}) | |
Constructor, which starts the timer. More... | |
~optimer () | |
Destructor, which invokes the report callback. More... | |
point | reset () |
Resets the timer back to zero and returns the previous tick value. More... | |
point | start () const |
Returns the start time point. More... | |
interval | elapsed () const |
Returns the elapsed time value. More... | |
interval | lap () |
Resets the starting tick and returns the elapsed time. More... | |
Private Attributes | |
point | start_ |
report_callback | repf_ |
Reports time elapsed at the end of an object scope.
The constructor accepts a callable that takes the optimer as its only argument, which can then be used to write the elapsed time to a stream, variable, or anything else that's desirable for a particular use case.
ResolutionType | Clock resolution – milliseconds, microseconds, etc. |
ClockType | Clock type – a monotonic clock by default. |
Definition at line 36 of file optimer.hpp.
using utils::optimer< ResolutionType, ClockType >::clock = ClockType |
Definition at line 38 of file optimer.hpp.
using utils::optimer< ResolutionType, ClockType >::interval = typename clock::duration |
Definition at line 41 of file optimer.hpp.
using utils::optimer< ResolutionType, ClockType >::point = typename clock::time_point |
Definition at line 40 of file optimer.hpp.
using utils::optimer< ResolutionType, ClockType >::report_callback = std::function<void(const optimer&)> |
Definition at line 42 of file optimer.hpp.
using utils::optimer< ResolutionType, ClockType >::resolution = ResolutionType |
Definition at line 39 of file optimer.hpp.
|
inlineexplicit |
Constructor, which starts the timer.
The report callback may be an empty object, in which case the destructor will not do anything. This may be useful in order to obtain and keep track of elapsed time manually for other purposes than console printing.
Definition at line 51 of file optimer.hpp.
|
inline |
Destructor, which invokes the report callback.
Definition at line 61 of file optimer.hpp.
References utils::optimer< ResolutionType, ClockType >::repf_.
|
inline |
Returns the elapsed time value.
Definition at line 81 of file optimer.hpp.
References utils::optimer< ResolutionType, ClockType >::start_.
Referenced by utils::operator<<().
|
inline |
Resets the starting tick and returns the elapsed time.
Definition at line 93 of file optimer.hpp.
References utils::optimer< ResolutionType, ClockType >::reset(), and utils::optimer< ResolutionType, ClockType >::start_.
|
inline |
Resets the timer back to zero and returns the previous tick value.
Definition at line 69 of file optimer.hpp.
References utils::optimer< ResolutionType, ClockType >::start_.
Referenced by utils::optimer< ResolutionType, ClockType >::lap().
|
inline |
Returns the start time point.
Definition at line 75 of file optimer.hpp.
References utils::optimer< ResolutionType, ClockType >::start_.
|
private |
Definition at line 101 of file optimer.hpp.
Referenced by utils::optimer< ResolutionType, ClockType >::~optimer().
|
private |