All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PLMD::Stopwatch Class Reference

Class implementing stopwatch to time execution. More...

#include <Stopwatch.h>

Classes

class  Time
 Class to hold the value of absolute time. More...
 
class  Watch
 Class to store a single stopwatch. More...
 

Public Member Functions

void start (const std::string &name)
 Start timer named "name". More...
 
void start ()
 
void stop (const std::string &name)
 Stop timer named "name". More...
 
void stop ()
 
void pause (const std::string &name)
 Pause timer named "name". More...
 
void pause ()
 

Private Member Functions

std::ostream & log (std::ostream &) const
 

Private Attributes

std::map< std::string, Watchwatches
 

Friends

std::ostream & operator<< (std::ostream &, const Stopwatch &)
 Dump all timers on an ostream. More...
 

Detailed Description

Class implementing stopwatch to time execution.

Each instance of this class is a container which can keep track of several named stopwatches at the same time. Access to the stopwatches is obtained using start(), stop(), pause() methods, giving as a parameter the name of the specific stopwatch. Also an empty string can be used (un-named stopwatch). Finally, all the times can be logged using << operator

#include "Stopwatch.h"

int main(){
  Stopwatch sw;
  sw.start();

  sw.start("initialization");
// do initialization ...
  sw.stop("initialization");

  for(int i=0;i<100;i++){
    sw.start("loop");
// do calculation
    sw.stop("loop");
  }

  sw.stop();
  return 0;
}

Using pause a stopwatch can be put on hold until the next start:

#include "Stopwatch.h"

int main(){
  Stopwatch sw;
  sw.start();

  sw.start("initialization");
// do initialization ...
  sw.stop("initialization");

  for(int i=0;i<100;i++){
    sw.start("loop");
// do calculation
    sw.pause("loop");
// here goes something that we do not want to include
    sw.start("loop");
// do calculation
    sw.stop("loop");
  }

  sw.stop();
  return 0;
}

Member Function Documentation

std::ostream & PLMD::Stopwatch::log ( std::ostream &  os) const
private
void PLMD::Stopwatch::pause ( const std::string &  name)

Pause timer named "name".

void PLMD::Stopwatch::pause ( )
inline
void PLMD::Stopwatch::start ( const std::string &  name)

Start timer named "name".

void PLMD::Stopwatch::start ( )
inline
void PLMD::Stopwatch::stop ( const std::string &  name)

Stop timer named "name".

void PLMD::Stopwatch::stop ( )
inline

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Stopwatch sw 
)
friend

Dump all timers on an ostream.

Member Data Documentation

std::map<std::string,Watch> PLMD::Stopwatch::watches
private

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