Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::Stopwatch Class Referenceabstract

Realizes a stopwatch for measuring elapsed time. More...

#include <ogdf/basic/Stopwatch.h>

+ Inheritance diagram for ogdf::Stopwatch:

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.
 

Detailed Description

Realizes a stopwatch for measuring elapsed time.

Definition at line 42 of file Stopwatch.h.

Constructor & Destructor Documentation

◆ Stopwatch() [1/2]

ogdf::Stopwatch::Stopwatch ( )
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.

◆ Stopwatch() [2/2]

ogdf::Stopwatch::Stopwatch ( int64_t  milliSecs)
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.

Parameters
milliSecsThe intial value of the total time in milliseconds.

Definition at line 62 of file Stopwatch.h.

◆ ~Stopwatch()

virtual ogdf::Stopwatch::~Stopwatch ( )
inlinevirtual

Definition at line 65 of file Stopwatch.h.

Member Function Documentation

◆ addCentiSeconds()

void ogdf::Stopwatch::addCentiSeconds ( int64_t  centiSeconds)
inline

Adds centiSeconds to total time.

Parameters
centiSecondsThe number of centiseconds to be added.

Definition at line 132 of file Stopwatch.h.

◆ centiSeconds()

int64_t ogdf::Stopwatch::centiSeconds ( ) const
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.

◆ exceeds()

bool ogdf::Stopwatch::exceeds ( int64_t  maxSeconds) const
inline

Returns true iff the currently elapsed time exceeds maxSeconds.

Definition at line 126 of file Stopwatch.h.

◆ hours()

int64_t ogdf::Stopwatch::hours ( ) const
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.

◆ milliSeconds()

int64_t ogdf::Stopwatch::milliSeconds ( ) const
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.

◆ minutes()

int64_t ogdf::Stopwatch::minutes ( ) const
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.

◆ reset()

void ogdf::Stopwatch::reset ( )
inline

Stops the stopwatch and sets its total time to 0.

Definition at line 82 of file Stopwatch.h.

◆ running()

bool ogdf::Stopwatch::running ( ) const
inline

Returns true if the stopwatch is running, false otherwise.

Definition at line 88 of file Stopwatch.h.

◆ seconds()

int64_t ogdf::Stopwatch::seconds ( ) const
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.

◆ start()

void ogdf::Stopwatch::start ( bool  reset = false)

Starts the stopwatch.

For safety reasons starting a running timer is an error.

Parameters
resetIf this flag is set to true, the stopwatch is reset before it is started.

◆ stop()

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.

◆ theTime()

virtual int64_t ogdf::Stopwatch::theTime ( ) const
protectedpure virtual

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.

Returns
The time since some starting point (e.g., the program start) in milliseconds.

Implemented in ogdf::StopwatchCPU, and ogdf::StopwatchWallClock.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Stopwatch stopwatch 
)
friend

Writes the currently elapsed time in the format hh:mm:ss.sec/100 to output stream os.

Parameters
osThe output stream.
stopwatchThe stopwatch whose elapsed time shall be written.
Returns
A reference to the output stream os.

Member Data Documentation

◆ m_running

bool ogdf::Stopwatch::m_running
private

true, if the timer is running.

Definition at line 45 of file Stopwatch.h.

◆ m_startTime

int64_t ogdf::Stopwatch::m_startTime
private

The start time of the timer in milliseconds.

Definition at line 43 of file Stopwatch.h.

◆ m_totalTime

int64_t ogdf::Stopwatch::m_totalTime
private

The total time in milliseconds.

Definition at line 44 of file Stopwatch.h.


The documentation for this class was generated from the following file: