All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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;
}

Definition at line 98 of file Stopwatch.h.

Member Function Documentation

std::ostream & PLMD::Stopwatch::log ( std::ostream &  os) const
private

Definition at line 142 of file Stopwatch.cpp.

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

Pause timer named "name".

Definition at line 137 of file Stopwatch.cpp.

void PLMD::Stopwatch::pause ( )
inline

Definition at line 157 of file Stopwatch.h.

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

Start timer named "name".

Definition at line 129 of file Stopwatch.cpp.

void PLMD::Stopwatch::start ( )
inline

Definition at line 147 of file Stopwatch.h.

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

Stop timer named "name".

Definition at line 133 of file Stopwatch.cpp.

void PLMD::Stopwatch::stop ( )
inline

Definition at line 152 of file Stopwatch.h.

Friends And Related Function Documentation

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

Dump all timers on an ostream.

Definition at line 50 of file Stopwatch.cpp.

Member Data Documentation

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

Definition at line 130 of file Stopwatch.h.


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