#include <Stopwatch.hpp>
A simple stopwatch class: time sections of code that execute repeatedly and get average execution time.
Stopwatch keeps track of cumulative time spent between all calls to start(label)
, stop(label)
pairs for the same label
, number of laps (calls of start/stop pairs), and cumulative time per lap.
For timing execution time between various checkpoints, use the Timer class.
Definition at line 31 of file Stopwatch.hpp.
Public Member Functions | |
void | start (const std::string &label) |
Starts the stopwatch with a given label. More... | |
void | stop (const std::string &label) |
Stops the stopwatch with a given label. More... | |
double | cumulativeTime (const std::string &label) const |
Returns total time of all laps for a given label. More... | |
int | numLaps (const std::string &label) const |
Returns number of laps for a given label. More... | |
double | timePerLap (const std::string &label) const |
Returns average time spent per lap. More... | |
bool | isRunning (const std::string &label) const |
Returns if stopwatch with a given label is currently running. More... | |
void | clear () |
Clear all stopwatch related data. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Stopwatch &stopwatch) |
Output average lap times for all labels. More... | |
Private Types | |
typedef std::chrono::steady_clock::time_point | time_type |
Time type. More... | |
Private Member Functions | |
int | getID (const std::string &label) const |
Returns the ID of stopwatch with a given label. More... | |
Private Attributes | |
std::vector< std::string > | labels |
List of stopwatch labels. More... | |
std::vector< double > | cumulative_time |
List of cumulative times for each stopwatch. More... | |
std::vector< int > | counts |
List of lap counts for each stopwatch. More... | |
std::vector< time_type > | times |
List of times for each stopwatch. More... | |
std::vector< bool > | currently_running |
For tracking when stopwatch is running. More... | |
void mm::Stopwatch::clear | ( | ) |
Clear all stopwatch related data.
Definition at line 67 of file Stopwatch.cpp.
double mm::Stopwatch::cumulativeTime | ( | const std::string & | label | ) | const |
Returns total time of all laps for a given label.
Definition at line 49 of file Stopwatch.cpp.
|
private |
Returns the ID of stopwatch with a given label.
Definition at line 13 of file Stopwatch.cpp.
|
inline |
Returns if stopwatch with a given label is currently running.
Definition at line 58 of file Stopwatch.hpp.
int mm::Stopwatch::numLaps | ( | const std::string & | label | ) | const |
Returns number of laps for a given label.
Definition at line 55 of file Stopwatch.cpp.
void mm::Stopwatch::start | ( | const std::string & | label | ) |
Starts the stopwatch with a given label.
Definition at line 19 of file Stopwatch.cpp.
void mm::Stopwatch::stop | ( | const std::string & | label | ) |
Stops the stopwatch with a given label.
Updates cumulative time and number of laps information for the given label. Individual lap durations are not saved.
Definition at line 37 of file Stopwatch.cpp.
double mm::Stopwatch::timePerLap | ( | const std::string & | label | ) | const |
Returns average time spent per lap.
Definition at line 61 of file Stopwatch.cpp.
|
friend |
Output average lap times for all labels.
Definition at line 76 of file Stopwatch.cpp.
|
private |
List of lap counts for each stopwatch.
Definition at line 35 of file Stopwatch.hpp.
|
private |
List of cumulative times for each stopwatch.
Definition at line 34 of file Stopwatch.hpp.
|
private |
For tracking when stopwatch is running.
Definition at line 37 of file Stopwatch.hpp.
|
private |
List of stopwatch labels.
Definition at line 33 of file Stopwatch.hpp.
|
private |
List of times for each stopwatch.
Definition at line 36 of file Stopwatch.hpp.