CARLsim
3.1.3
CARLsim: a GPU-accelerated SNN simulator
|
Utility to measure script execution time (wall-clock time) in milliseconds. More...
#include <stopwatch.h>
Public Member Functions | |
Stopwatch (bool startTimer=true) | |
Utility to measure script execution time (wall-clock time) in milliseconds. More... | |
~Stopwatch () | |
Stopwatch destructor. More... | |
uint64_t | getLapTime (const std::string &tag) const |
Looks up the execution time of a lap by its tag. More... | |
uint64_t | getLapTime (int index) const |
Looks up the execution time of a lap by its vector index. More... | |
uint64_t | lap (const std::string &tag="") |
Ends the current lap and starts a new lap. More... | |
void | print (FILE *fileStream=NULL) const |
Prints a summary to file or console. More... | |
void | reset () |
Resets the timer. More... | |
void | start (const std::string &tag="") |
Starts/restarts the timer. More... | |
uint64_t | stop (bool printMessage=true, FILE *printFile=NULL) |
Stops the timer. More... | |
This class provides a means to measure script execution time (wall-clock time) with millisecond precision.
The stopwatch can start, stop, and lap. It can be used to time different segments of a simulation; for example, to record the time it took to build a network vs. the time it took to run the network. Every segment (or lap) can be annotated with a user-defined string for easier analysis. The method Stopwatch::lap does also return the execution time for the previous lap. Stopwatch::stop also returns the accumulated record time over all laps.
Code example:
Stopping the stopwatch will produce nicely formatted console output indicating the starting and stopping time of each lap, as well as the accumulated time.
Definition at line 67 of file stopwatch.h.
Stopwatch | ( | bool | startTimer = true | ) |
This class provides a means to measure script execution time (wall-clock time) with millisecond precision.
By default, calling the constructor will also start the timer. Optionally, startTimer
can be set to false. In this case, the first call to Stopwatch::start will start the timer.
startTimer | flag to indicate whether to automatically start the timer (true) or not (false) |
~Stopwatch | ( | ) |
The destructor deallocates all data structures.
uint64_t getLapTime | ( | const std::string & | tag | ) | const |
This method looks up a certain lap by its specified tag, and if found, returns the lap's recorded execution time. If the tag cannot be found, a warning is printed and value 0 is returned.
tag | user-defined string name of the lap to look up |
uint64_t getLapTime | ( | int | index | ) | const |
This method looks up a certain lap by its position in the list of all recorded laps (0-indexed). For example, the first lap will have index 0, the second will have index 1, and so on. If the index is valid, the method returns the lap's recorded execution time. If the index is invalid, a warning is printed and value 0 is returned.
index | index of the lap in the list of recorded laps |
uint64_t lap | ( | const std::string & | tag = "" | ) |
This method ends the current lap and starts a new lap. The new lap can be given a user-defined string for a tag.
This method is equivalent to calling Stopwatch::stop and Stopwatch::start.
The method will also return the execution time of the just-ended lap.
tag | user-defined string name for the new lap |
void print | ( | FILE * | fileStream = NULL | ) | const |
This method prints a summary to either file or console, depending on optional argument fileStream
. By default, fileStream
is NULL
, making the stream redirect to stdout.
Example output:
Each lap is presented on its own row, annotated by its tag. The start time of the first lap is always 0. All other times are reported relative to that start time. The time format is: number of hours:number of minutes:number of second.number of milliseconds. The column "Total" contains the recorded execution time accumulated over all laps.
fileStream | file stream where to print the summary (default: NULL, which redirects stream to stdout) |
void reset | ( | ) |
This method resets the timer, effectively deleting all previously recorded data.
void start | ( | const std::string & | tag = "" | ) |
This method starts a new lap. The lap can be given a user-defined string for a tag.
A timer can (theoretically) handle an arbitrary number of start/stop cycles.
tag | user-defined string name for the new lap |
uint64_t stop | ( | bool | printMessage = true , |
FILE * | printFile = NULL |
||
) |
This method ends a lap. By default, the method will also print a summary to a file (which is stdout by default). Optionally, the print mechanism can be turned off, or the file stream redirected.
A timer can (theoretically) handle an arbitrary number of start/stop cycles.
The method will also return the total accumulated time (ms) over all recorded laps.
printMessage | flag to indicate whether to print a record summary (true) or not (false) |
printFile | file stream where to print the summary (by default: NULL, redirects to stdout) |