Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Stopwatch.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/basic.h>
35
36namespace ogdf {
37
39
45 bool m_running;
46
47public:
49
53 Stopwatch() : m_startTime(0), m_totalTime(0), m_running(false) { }
54
56
63 : m_startTime(0), m_totalTime(milliSecs), m_running(false) { }
64
65 virtual ~Stopwatch() { }
66
68
73 void start(bool reset = false);
74
76
79 void stop();
80
82 void reset() {
83 m_running = false;
84 m_totalTime = 0;
85 }
86
88 bool running() const { return m_running; }
89
91
95 return m_running ? m_totalTime + theTime() - m_startTime : m_totalTime;
96 }
97
99
102 int64_t centiSeconds() const { return milliSeconds() / 10; }
103
105
109 int64_t seconds() const { return milliSeconds() / 1000; }
110
112
116 int64_t minutes() const { return seconds() / 60; }
117
119
123 int64_t hours() const { return seconds() / 3600; }
124
126 bool exceeds(int64_t maxSeconds) const { return seconds() >= maxSeconds; }
127
129
132 void addCentiSeconds(int64_t centiSeconds) { m_totalTime += 10 * centiSeconds; }
133
135
140 friend OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const Stopwatch& stopwatch);
141
142protected:
144
150 virtual int64_t theTime() const = 0;
151};
152
155public:
157
162
164
171
172 virtual ~StopwatchCPU() { }
173
174private:
176 virtual int64_t theTime() const override;
177};
178
181public:
183
188
190
197
199
200private:
202 virtual int64_t theTime() const override;
203};
204
205}
Basic declarations, included by all source files.
Implements a stopwatch measuring CPU time.
Definition Stopwatch.h:154
virtual ~StopwatchCPU()
Definition Stopwatch.h:172
StopwatchCPU(int64_t milliSecs)
Creates a stopwatch for measuring CPU time and sets its total time to milliSecs.
Definition Stopwatch.h:170
StopwatchCPU()
Creates a stopwatch for measuring CPU time with total time 0.
Definition Stopwatch.h:161
virtual int64_t theTime() const override
Returns the current CPU time in milliseconds (from some fixed starting point).
Realizes a stopwatch for measuring elapsed time.
Definition Stopwatch.h:42
int64_t m_totalTime
The total time in milliseconds.
Definition Stopwatch.h:44
friend 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.
int64_t hours() const
Returns the currently elapsed time in hours.
Definition Stopwatch.h:123
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition Stopwatch.h:102
Stopwatch()
Initializes a stop watch with total time 0.
Definition Stopwatch.h:53
bool m_running
true, if the timer is running.
Definition Stopwatch.h:45
int64_t m_startTime
The start time of the timer in milliseconds.
Definition Stopwatch.h:43
void start(bool reset=false)
Starts the stopwatch.
Stopwatch(int64_t milliSecs)
Initializes a stopwatch and sets its total time to milliSecs.
Definition Stopwatch.h:62
void addCentiSeconds(int64_t centiSeconds)
Adds centiSeconds to total time.
Definition Stopwatch.h:132
void reset()
Stops the stopwatch and sets its total time to 0.
Definition Stopwatch.h:82
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition Stopwatch.h:109
void stop()
Stops the stopwatch and adds the difference between the current time and the starting time to the tot...
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition Stopwatch.h:116
bool exceeds(int64_t maxSeconds) const
Returns true iff the currently elapsed time exceeds maxSeconds.
Definition Stopwatch.h:126
bool running() const
Returns true if the stopwatch is running, false otherwise.
Definition Stopwatch.h:88
int64_t milliSeconds() const
Returns the currently elapsed time in milliseconds.
Definition Stopwatch.h:94
virtual ~Stopwatch()
Definition Stopwatch.h:65
virtual int64_t theTime() const =0
Returns the current time in milliseconds (from some fixed starting point).
Implements a stopwatch measuring wall-clock time.
Definition Stopwatch.h:180
StopwatchWallClock()
Creates a stopwatch for measuring wall-clock time with total time 0.
Definition Stopwatch.h:187
StopwatchWallClock(int64_t milliSecs)
Creates a stopwatch for measuring wall-clock time and sets its total time to milliSecs.
Definition Stopwatch.h:196
virtual int64_t theTime() const override
Returns the current wall-clock time in milliseconds (from some fixed starting point).
virtual ~StopwatchWallClock()
Definition Stopwatch.h:198
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.