A generic timer class. More...
Public Member Functions | |
timer () | |
Constructor which does not start measuring the time. More... | |
timer (const Outputter &outputter) | |
Constructor which starts measuring the time. More... | |
void | start (const Outputter &outputter) |
Delayed start. More... | |
void | set_measure_method (unsigned method) |
Specify the measure method. More... | |
Outputter::result_type | operator() () const |
Intermediate Call of the timer functor. More... | |
virtual | ~timer () |
Deconstructor which stops measuring the time. More... | |
A generic timer class.
This class measures the time between its constructor and its deconstructor is called. In the deconstructor a functor is called which can be assigned in the constructor.
Because of this design the code for which the run-time has to be checked has to be enclosed as a block and the timer needs to be initialized as local variable in the beginning of the block, so that the deconstructor get called automatically at the end of the block.
The Outputter has to implement operator()(double runtime) const.
Two functors are already implemented in the library:
This example demonstrates how to create a timer functor which outputs the run-time to STDOUT and how to use the timer class with that functor.
It is important to specify a result_type which is the result of the () operator.
|
inline |
Constructor which does not start measuring the time.
When delayed starting should be done (using start(const Outputter&)) this constructor has to be used.
|
inlineexplicit |
Constructor which starts measuring the time.
The outputter
is copied and called in the deconstructor with the measured time.
outputter | Functor which does something with the measured run-time |
|
inlinevirtual |
Deconstructor which stops measuring the time.
In this function time is measured again and the functor is called with the runtime.
|
inline |
Intermediate Call of the timer functor.
This operator also returns the return type of the functor. This is useful, when using the reference_timer which returns the value of the reference in the functor call.
In this function the timer is used explicitly without a scope and the start method as well as the intermediate operator.
|
inline |
Specify the measure method.
Use the flags of the timer class to specify the measure method, e.g. measure_method::user_time or measure_method::system_time. The flags can also be merged to capture both and return the sum, i.e. measure_method::user_time | measure_method::system_time.
|
inline |
Delayed start.
There might be reasons when the starting of the measurement should be delayed and not started with the constructor. For this cases this method can be used.
outputter | Functor which does something with the measured run-time |