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... | |
void | reset () |
Resets the timer back to zero. More... | |
point | start () const |
Returns the start time point. More... | |
interval | elapsed () const |
Returns the elapsed time value. 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 35 of file optimer.hpp.
using util::optimer< ResolutionType, ClockType >::clock = ClockType |
Definition at line 37 of file optimer.hpp.
using util::optimer< ResolutionType, ClockType >::interval = typename clock::duration |
Definition at line 40 of file optimer.hpp.
using util::optimer< ResolutionType, ClockType >::point = typename clock::time_point |
Definition at line 39 of file optimer.hpp.
using util::optimer< ResolutionType, ClockType >::report_callback = std::function<void(const optimer&)> |
Definition at line 41 of file optimer.hpp.
using util::optimer< ResolutionType, ClockType >::resolution = ResolutionType |
Definition at line 38 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 50 of file optimer.hpp.
|
inline |
Destructor, which invokes the report callback.
Definition at line 60 of file optimer.hpp.
References util::optimer< ResolutionType, ClockType >::repf_.
|
inline |
Returns the elapsed time value.
Definition at line 80 of file optimer.hpp.
References util::optimer< ResolutionType, ClockType >::start_.
|
inline |
Resets the timer back to zero.
Definition at line 68 of file optimer.hpp.
References util::optimer< ResolutionType, ClockType >::start_.
|
inline |
Returns the start time point.
Definition at line 74 of file optimer.hpp.
References util::optimer< ResolutionType, ClockType >::start_.
|
private |
Definition at line 87 of file optimer.hpp.
Referenced by util::optimer< ResolutionType, ClockType >::~optimer().
|
private |
Definition at line 86 of file optimer.hpp.
Referenced by util::optimer< ResolutionType, ClockType >::elapsed(), util::optimer< ResolutionType, ClockType >::reset(), and util::optimer< ResolutionType, ClockType >::start().