Realizes a stopwatch for measuring elapsed time. More...
#include <ogdf/basic/Stopwatch.h>
Public Member Functions | |
Stopwatch () | |
Initializes a stop watch with total time 0. | |
Stopwatch (int64_t milliSecs) | |
Initializes a stopwatch and sets its total time to milliSecs . | |
virtual | ~Stopwatch () |
void | addCentiSeconds (int64_t centiSeconds) |
Adds centiSeconds to total time. | |
int64_t | centiSeconds () const |
Returns the currently elapsed time in 1/100-seconds. | |
bool | exceeds (int64_t maxSeconds) const |
Returns true iff the currently elapsed time exceeds maxSeconds . | |
int64_t | hours () const |
Returns the currently elapsed time in hours. | |
int64_t | milliSeconds () const |
Returns the currently elapsed time in milliseconds. | |
int64_t | minutes () const |
Returns the currently elapsed time in minutes. | |
void | reset () |
Stops the stopwatch and sets its total time to 0. | |
bool | running () const |
Returns true if the stopwatch is running, false otherwise. | |
int64_t | seconds () const |
Returns the currently elapsed time in seconds. | |
void | start (bool reset=false) |
Starts the stopwatch. | |
void | stop () |
Stops the stopwatch and adds the difference between the current time and the starting time to the total time. | |
Protected Member Functions | |
virtual int64_t | theTime () const =0 |
Returns the current time in milliseconds (from some fixed starting point). | |
Private Attributes | |
bool | m_running |
true, if the timer is running. | |
int64_t | m_startTime |
The start time of the timer in milliseconds. | |
int64_t | m_totalTime |
The total time in milliseconds. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Stopwatch &stopwatch) |
Writes the currently elapsed time in the format hh:mm:ss.sec/100 to output stream os . | |
Realizes a stopwatch for measuring elapsed time.
Definition at line 42 of file Stopwatch.h.
|
inline |
Initializes a stop watch with total time 0.
After creation the stopwatch is not running, i.e., it has to be started explicitly for measuring time.
Definition at line 53 of file Stopwatch.h.
|
inlineexplicit |
Initializes a stopwatch and sets its total time to milliSecs
.
After creation the stopwatch is not running, i.e., it has to be started explicitly for measuring time.
milliSecs | The intial value of the total time in milliseconds. |
Definition at line 62 of file Stopwatch.h.
|
inlinevirtual |
Definition at line 65 of file Stopwatch.h.
Adds centiSeconds
to total time.
centiSeconds | The number of centiseconds to be added. |
Definition at line 132 of file Stopwatch.h.
|
inline |
Returns the currently elapsed time in 1/100-seconds.
It is not necessary to stop the timer to get the correct time.
Definition at line 102 of file Stopwatch.h.
Returns true iff the currently elapsed time exceeds maxSeconds
.
Definition at line 126 of file Stopwatch.h.
|
inline |
Returns the currently elapsed time in hours.
It is not necessary to stop the timer to get the correct time. The result is rounded down to the next integer value.
Definition at line 123 of file Stopwatch.h.
|
inline |
Returns the currently elapsed time in milliseconds.
It is not necessary to stop the timer to get the correct time.
Definition at line 94 of file Stopwatch.h.
|
inline |
Returns the currently elapsed time in minutes.
It is not necessary to stop the timer to get the correct time. The result is rounded down to the next integer value.
Definition at line 116 of file Stopwatch.h.
|
inline |
Stops the stopwatch and sets its total time to 0.
Definition at line 82 of file Stopwatch.h.
|
inline |
Returns true if the stopwatch is running, false otherwise.
Definition at line 88 of file Stopwatch.h.
|
inline |
Returns the currently elapsed time in seconds.
It is not necessary to stop the timer to get the correct time. The result is rounded down to the next integer value.
Definition at line 109 of file Stopwatch.h.
Starts the stopwatch.
For safety reasons starting a running timer is an error.
reset | If this flag is set to true, the stopwatch is reset before it is started. |
void ogdf::Stopwatch::stop | ( | ) |
Stops the stopwatch and adds the difference between the current time and the starting time to the total time.
Stopping a non-running stopwatch is an error.
Returns the current time in milliseconds (from some fixed starting point).
This pure virtual function is used for measuring time differences. It must be implemented in derived classes.
Implemented in ogdf::StopwatchCPU, and ogdf::StopwatchWallClock.
Writes the currently elapsed time in the format hh:mm:ss.sec/100
to output stream os
.
os | The output stream. |
stopwatch | The stopwatch whose elapsed time shall be written. |
os
.
|
private |
true, if the timer is running.
Definition at line 45 of file Stopwatch.h.
|
private |
The start time of the timer in milliseconds.
Definition at line 43 of file Stopwatch.h.
|
private |
The total time in milliseconds.
Definition at line 44 of file Stopwatch.h.