CVR-Lib last update 20 Sep 2009

cvr::timer Class Reference

The timer allows to measure time with a precision of about 30us on Linux systems and a value dependent on the performance counter on Windows systems. More...

#include <cvrTimer.h>

Inheritance diagram for cvr::timer:

Inheritance graph
[legend]
Collaboration diagram for cvr::timer:

Collaboration graph
[legend]

List of all members.

Public Types

enum  eTimeType { Wall, Cpu }

Public Member Functions

 timer ()
 timer (const eTimeType &timeType)
 timer (const timer &other)
virtual ~timer ()
void start ()
void stop ()
double getTime () const
void setTimeType (const eTimeType &timeType)
const eTimeTypegetTimeType ()
virtual const std::string & name () const
virtual timerclone () const
virtual timernewInstance () const

Static Public Member Functions

static std::string getDateAndTime ()
static double getCpuTime ()

Protected Member Functions

double getActualTime () const

Protected Attributes

eTimeType timeType_
double startTime_
double endTime_
bool started_


Detailed Description

The timer allows to measure time with a precision of about 30us on Linux systems and a value dependent on the performance counter on Windows systems.

It seems like the precision for CPU time is 1ms on Windows systems. The elapsed time is returned in microseconds.

Depending on the eTimeType (setTimeType()) The CPU time (Cpu) or wall-clock time (Wall) are measured. The default is Cpu.

The maximum time that can be measured with this function in Wall mode is 1 day (86.4E+09 microseconds). To measure longer time intervalls use the standard time() function.

Example:

 cvr::timer chron;

 chron.start();

 // do something

 chron.stop();

 std::cout << "something takes " << chron.getTime() << " microseconds\n";

Member Enumeration Documentation

Determines which time is measured.

Enumerator:
Wall  Use Wall-time.
Cpu  Use CPU time.


Constructor & Destructor Documentation

cvr::timer::timer (  ) 

Default constructor.

cvr::timer::timer ( const eTimeType timeType  ) 

Constructor to set the time type.

cvr::timer::timer ( const timer other  ) 

Copy constructor.

virtual cvr::timer::~timer (  )  [virtual]

Destructor.


Member Function Documentation

virtual timer* cvr::timer::clone (  )  const [virtual]

Clone method.

Implements cvr::object.

double cvr::timer::getActualTime (  )  const [protected]

Get actual time.

The implementation of this method depends on the OS.

static double cvr::timer::getCpuTime (  )  [static]

Returns the current CPU time in usec.

Don't use this function for time measurement. Use start(), stop(), getTime() instead.

static std::string cvr::timer::getDateAndTime (  )  [static]

Return a string containing the current time.

Obviously this always uses the Wall time.

The format is the one return by the libc function ctime, for example

 Sat Jul 24 22:46:18 CEST 2004

double cvr::timer::getTime (  )  const

Get the elapsed time (in microsecond) between start() and stop() or the actual time (if stop() is not been called yet!).

Returns:
Elapsed time

const eTimeType& cvr::timer::getTimeType (  ) 

Returns the current time type.

Returns:
the current eTimeType.

virtual const std::string& cvr::timer::name (  )  const [virtual]

Class name.

Implements cvr::object.

virtual timer* cvr::timer::newInstance (  )  const [virtual]

New instance method.

Implements cvr::object.

void cvr::timer::setTimeType ( const eTimeType timeType  ) 

Sets the time type.

Parameters:
timeType the new eTimeType

void cvr::timer::start (  ) 

Start the timer.

void cvr::timer::stop (  ) 

Stop the timer.


Member Data Documentation

double cvr::timer::endTime_ [protected]

Time at which stop() was called.

bool cvr::timer::started_ [protected]

Flag to indicate if start() was called, but not stop().

double cvr::timer::startTime_ [protected]

Time at which start() was called.

Time type used.


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

Generated on Sun Sep 20 22:09:06 2009 for CVR-Lib by Doxygen 1.5.8