Utilities Package
Version Linux2023.0
|
For measuring the time taken by an algorithm to perform its task. More...
#include <utilities.h>
Public Member Functions | |
Stopwatch () | |
Default constructor. More... | |
Stopwatch (const string nameOfEventToBeTimed) | |
Constructor which allows the naming of the event to be timed. More... | |
void | setEventName (const string nameOfEventToBeTimed) |
Sets, or resets, the name of the event to be timed. More... | |
string | getEventName () const |
Gets the current name of the event to be timed. More... | |
void | start () |
Causes the stopwatch to start running. More... | |
void | stop () |
Causes the stopwatch to stop running. More... | |
void | delay (int delayFactor=1) const |
Adds some multiple of an artifical amount of time to the accumulated time on the stopwatch. More... | |
clock_t | getTicks () const |
Gets the number of clock ticks between the most recent calls of start() and stop(). More... | |
double | getSeconds () const |
Gets the number of seconds between the last calls of start() and stop(). More... | |
double | getMinutes () const |
Gets the number of minutes between the last calls of start() and stop(). More... | |
double | getHours () const |
Gets the number of hours between the last calls of start() and stop(). More... | |
void | display () const |
For measuring the time taken by an algorithm to perform its task.
An object of class Stopwatch
will behave like a stopwatch. It can be started, stopped, and asked for the time elapsed. This time can be computer time (clock ticks), or real time as measured in seconds, minutes, or hours.
Scobey::Stopwatch::Stopwatch | ( | ) |
Default constructor.
Scobey::Stopwatch::Stopwatch | ( | const string | nameOfEventToBeTimed | ) |
Constructor which allows the naming of the event to be timed.
void Scobey::Stopwatch::setEventName | ( | const string | nameOfEventToBeTimed | ) |
Sets, or resets, the name of the event to be timed.
string Scobey::Stopwatch::getEventName | ( | ) | const |
Gets the current name of the event to be timed.
void Scobey::Stopwatch::start | ( | ) |
void Scobey::Stopwatch::stop | ( | ) |
void Scobey::Stopwatch::delay | ( | int | delayFactor = 1 | ) | const |
Adds some multiple of an artifical amount of time to the accumulated time on the stopwatch.
start()
has been called. clock_t Scobey::Stopwatch::getTicks | ( | ) | const |
double Scobey::Stopwatch::getSeconds | ( | ) | const |
double Scobey::Stopwatch::getMinutes | ( | ) | const |
double Scobey::Stopwatch::getHours | ( | ) | const |
void Scobey::Stopwatch::display | ( | ) | const |
Displays the time, in hours (as an integer value), minutes (as an integer value), and seconds (as a double value), between the last time this <tt>%Stopwatch</tt> object was started and stopped. @pre <em>start()</em> and <em>stop()</em> must have been called, in that order. @post - Case 1: If no name has been given to the event that has just been timed, the ouput displayed is this:
Total time elapsed = hh:mm:ss.sss
Total time elapsed for event name-of-event = hh:mm:ss.sss