timer< Outputter > Class Template Reference

A generic timer class. More...

List of all members.

Public Member Functions

 timer ()
 Constructor which does not start measuring the time.
 timer (const Outputter &outputter)
 Constructor which starts measuring the time.
void start (const Outputter &outputter)
 Delayed start.
Outputter::result_type operator() ()
 Intermediate Call of the timer functor.
virtual ~timer ()
 Deconstructor which stops measuring the time.

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()()
 #include <core/utils/timer.hpp>

 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;
   revkit::timer<output_timer> t( 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  )  [inline, explicit]

Constructor which starts measuring the time.

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

Parameters:
outputter Functor which does something with the measured run-time
Author:
RevKit
Since:
1.0
virtual ~timer (  )  [inline, virtual]

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() (  )  [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 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:
outputter Functor 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 Fri Jul 2 07:50:42 2010 for by doxygen 1.6.3