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, Watch > | watches |
Friends | |
std::ostream & | operator<< (std::ostream &, const Stopwatch &) |
Dump all timers on an ostream. More... | |
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; }
|
private |
void PLMD::Stopwatch::pause | ( | const std::string & | name | ) |
Pause timer named "name".
|
inline |
void PLMD::Stopwatch::start | ( | const std::string & | name | ) |
Start timer named "name".
|
inline |
void PLMD::Stopwatch::stop | ( | const std::string & | name | ) |
Stop timer named "name".
|
inline |
|
friend |
Dump all timers on an ostream.
|
private |
Hosted by GitHub | 1.8.7 |