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; }
Definition at line 98 of file Stopwatch.h.
|
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.
|
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.
|
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.
|
inline |
Definition at line 152 of file Stopwatch.h.
|
friend |
Dump all timers on an ostream.
Definition at line 50 of file Stopwatch.cpp.
|
private |
Definition at line 130 of file Stopwatch.h.
Hosted by GitHub
![]() |
![]() |