List of all members | Public Member Functions
timer< Outputter > Class Template Reference

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...
 

Detailed Description

template<typename Outputter>
class revkit::timer< Outputter >

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:

Example

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.

See Also
timer::operator()()
struct output_timer {
typedef void result_type;
void operator()( double runtime ) const {
std::cout << runtime << std::endl;
}
};
...
// some other code for which no time should be measured
{
output_timer ot;
// code for which time should be measured
}
// some other code for which no time should be measured
Author
RevKit
Since
1.0

Constructor & Destructor Documentation

timer ( )
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.

Author
RevKit
Since
1.0
timer ( const Outputter &  outputter)
inlineexplicit

Constructor which starts measuring the time.

The outputter is copied and called in the deconstructor with the measured time.

Parameters
outputterFunctor which does something with the measured run-time
Author
RevKit
Since
1.0
virtual ~timer ( )
inlinevirtual

Deconstructor which stops measuring the time.

In this function time is measured again and the functor is called with the runtime.

Author
RevKit
Since
1.0

Member Function Documentation

Outputter::result_type operator() ( ) const
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.

Example

In this function the timer is used explicitly without a scope and the start method as well as the intermediate operator.

double runtime;
reference_timer rt( &runtime );
timer<reference_timer> t;
// before starting the measurement
t.start( rt );
// calculate a bit
double intermediate_time = t();
// calculate a bit more
intermediate_time = t();
Returns
The result value of the functor operator (if available)
Author
RevKit
Since
1.0
void set_measure_method ( unsigned  method)
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.

Author
RevKit
Since
1.1
void start ( const Outputter &  outputter)
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.

Parameters
outputterFunctor which does something with the measured run-time
Author
RevKit
Since
1.0

The documentation for this class was generated from the following file:

Generated on Tue Apr 16 2013 08:12:02 for RevKit by doxygen 1.8.3.1