Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Stopwatch.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 
36 namespace ogdf {
37 
39 
43  int64_t m_startTime;
44  int64_t m_totalTime;
45  bool m_running;
46 
47 public:
49 
53  Stopwatch() : m_startTime(0), m_totalTime(0), m_running(false) { }
54 
56 
62  explicit Stopwatch(int64_t milliSecs)
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 
94  int64_t milliSeconds() const {
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 
142 protected:
144 
150  virtual int64_t theTime() const = 0;
151 };
152 
155 public:
157 
162 
164 
170  explicit StopwatchCPU(int64_t milliSecs) : Stopwatch(milliSecs) { }
171 
172  virtual ~StopwatchCPU() { }
173 
174 private:
176  virtual int64_t theTime() const override;
177 };
178 
181 public:
183 
188 
190 
196  explicit StopwatchWallClock(int64_t milliSecs) : Stopwatch(milliSecs) { }
197 
198  virtual ~StopwatchWallClock() { }
199 
200 private:
202  virtual int64_t theTime() const override;
203 };
204 
205 }
ogdf::Stopwatch::milliSeconds
int64_t milliSeconds() const
Returns the currently elapsed time in milliseconds.
Definition: Stopwatch.h:94
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::StopwatchWallClock
Implements a stopwatch measuring wall-clock time.
Definition: Stopwatch.h:180
ogdf::StopwatchWallClock::StopwatchWallClock
StopwatchWallClock()
Creates a stopwatch for measuring wall-clock time with total time 0.
Definition: Stopwatch.h:187
backward::Color::reset
@ reset
Definition: backward.hpp:1719
ogdf::Stopwatch::m_startTime
int64_t m_startTime
The start time of the timer in milliseconds.
Definition: Stopwatch.h:43
ogdf::Stopwatch::~Stopwatch
virtual ~Stopwatch()
Definition: Stopwatch.h:65
ogdf::StopwatchCPU
Implements a stopwatch measuring CPU time.
Definition: Stopwatch.h:154
ogdf::Stopwatch::hours
int64_t hours() const
Returns the currently elapsed time in hours.
Definition: Stopwatch.h:123
ogdf::StopwatchCPU::StopwatchCPU
StopwatchCPU()
Creates a stopwatch for measuring CPU time with total time 0.
Definition: Stopwatch.h:161
ogdf::Stopwatch::addCentiSeconds
void addCentiSeconds(int64_t centiSeconds)
Adds centiSeconds to total time.
Definition: Stopwatch.h:132
ogdf::Stopwatch::Stopwatch
Stopwatch(int64_t milliSecs)
Initializes a stopwatch and sets its total time to milliSecs.
Definition: Stopwatch.h:62
ogdf::Stopwatch::seconds
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition: Stopwatch.h:109
ogdf::Stopwatch::Stopwatch
Stopwatch()
Initializes a stop watch with total time 0.
Definition: Stopwatch.h:53
ogdf::Stopwatch::m_totalTime
int64_t m_totalTime
The total time in milliseconds.
Definition: Stopwatch.h:44
ogdf::StopwatchWallClock::StopwatchWallClock
StopwatchWallClock(int64_t milliSecs)
Creates a stopwatch for measuring wall-clock time and sets its total time to milliSecs.
Definition: Stopwatch.h:196
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:978
ogdf::Stopwatch::minutes
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition: Stopwatch.h:116
ogdf::Stopwatch::centiSeconds
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition: Stopwatch.h:102
ogdf::Stopwatch::running
bool running() const
Returns true if the stopwatch is running, false otherwise.
Definition: Stopwatch.h:88
ogdf::Stopwatch::m_running
bool m_running
true, if the timer is running.
Definition: Stopwatch.h:45
ogdf::StopwatchCPU::~StopwatchCPU
virtual ~StopwatchCPU()
Definition: Stopwatch.h:172
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::Stopwatch
Realizes a stopwatch for measuring elapsed time.
Definition: Stopwatch.h:42
ogdf::StopwatchCPU::StopwatchCPU
StopwatchCPU(int64_t milliSecs)
Creates a stopwatch for measuring CPU time and sets its total time to milliSecs.
Definition: Stopwatch.h:170
ogdf::StopwatchWallClock::~StopwatchWallClock
virtual ~StopwatchWallClock()
Definition: Stopwatch.h:198
ogdf::Stopwatch::reset
void reset()
Stops the stopwatch and sets its total time to 0.
Definition: Stopwatch.h:82
ogdf::Stopwatch::exceeds
bool exceeds(int64_t maxSeconds) const
Returns true iff the currently elapsed time exceeds maxSeconds.
Definition: Stopwatch.h:126