DP3
Classes | Public Member Functions | List of all members
dp3::common::BaseTimer< Clock > Class Template Reference

Very accurate timer for elapsed times. More...

#include <Timer.h>

Classes

class  StartStop
 Internal class to do an automatic start/stop. More...
 

Public Member Functions

 BaseTimer (const std::string &name=std::string())
 
double getAverage () const
 Get the average time (in seconds) between start/stop. More...
 
uint64_t getCount () const
 Get the total number of times start/stop is done. More...
 
double getElapsed () const
 Get the elapsed time (in seconds). More...
 
BaseTimeroperator+= (const BaseTimer &other)
 Accumulate timer statistics. More...
 
std::ostream & print (std::ostream &str) const
 Prints the timer. More...
 
void reset ()
 Resets the timer to zero. More...
 
void start ()
 Starts the timer. More...
 
void stop ()
 Stops the timer. More...
 

Detailed Description

template<class Clock>
class dp3::common::BaseTimer< Clock >

Very accurate timer for elapsed times.

Put timer.start() and timer.stop() calls around the piece of code to be timed; make sure that start() and stop() calls alternate. A timer can be started and stopped multiple times; both the average and total time, as well as the number of iterations are printed. The measured time is real time (as opposed to user or system time). The timer can be used to measure from 1 nanosecond to a century interval. The accuracy of the timer depends on the platform.

The internal RAII class StartStop can be used to do the start/stop. The constructor starts the timer, while the destructor stops it. It has the advantage that no explicit stop has to be given. Moreover, it makes the start/stop exception-safe.

Template Parameters
ClockClock type, which meets the Clock named requirements. This argument allows using a mocked clock.

Constructor & Destructor Documentation

◆ BaseTimer()

template<class Clock >
dp3::common::BaseTimer< Clock >::BaseTimer ( const std::string &  name = std::string())
inlineexplicit

Constructor.

Parameters
nameThe name that will be used when printing the timer.

Member Function Documentation

◆ getAverage()

template<class Clock >
double dp3::common::BaseTimer< Clock >::getAverage ( ) const
inline

Get the average time (in seconds) between start/stop.

◆ getCount()

template<class Clock >
uint64_t dp3::common::BaseTimer< Clock >::getCount ( ) const
inline

Get the total number of times start/stop is done.

◆ getElapsed()

template<class Clock >
double dp3::common::BaseTimer< Clock >::getElapsed ( ) const
inline

Get the elapsed time (in seconds).

◆ operator+=()

template<class Clock >
BaseTimer& dp3::common::BaseTimer< Clock >::operator+= ( const BaseTimer< Clock > &  other)
inline

Accumulate timer statistics.

◆ print()

template<class Clock >
std::ostream& dp3::common::BaseTimer< Clock >::print ( std::ostream &  str) const
inline

Prints the timer.

◆ reset()

template<class Clock >
void dp3::common::BaseTimer< Clock >::reset ( )
inline

Resets the timer to zero.

◆ start()

template<class Clock >
void dp3::common::BaseTimer< Clock >::start ( )
inline

Starts the timer.

◆ stop()

template<class Clock >
void dp3::common::BaseTimer< Clock >::stop ( )
inline

Stops the timer.


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