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  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::unordered_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

◆ log()

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

◆ pause() [1/2]

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

Pause timer named "name".

◆ pause() [2/2]

void PLMD::Stopwatch::pause ( )
inline

◆ start() [1/2]

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

Start timer named "name".

◆ start() [2/2]

void PLMD::Stopwatch::start ( )
inline

◆ stop() [1/2]

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

Stop timer named "name".

◆ stop() [2/2]

void PLMD::Stopwatch::stop ( )
inline

Friends And Related Function Documentation

◆ operator<<

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

Dump all timers on an ostream.

Member Data Documentation

◆ watches

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

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