Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

Stopwatch.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 
36 
37 namespace ogdf {
38 
40 
44 
45  int64_t m_startTime;
46  int64_t m_totalTime;
47  bool m_running;
48 
49 public:
51 
55  Stopwatch() : m_startTime(0), m_totalTime(0), m_running(false) { }
56 
58 
64  explicit Stopwatch(int64_t milliSecs) : m_startTime(0), m_totalTime(milliSecs), m_running(false) { }
65 
66 
67  virtual ~Stopwatch() { }
68 
69 
71 
76  void start(bool reset = false);
77 
79 
82  void stop();
83 
85  void reset() {
86  m_running = false;
87  m_totalTime = 0;
88  }
89 
90 
92  bool running() const { return m_running; }
93 
94 
96 
99  int64_t milliSeconds() const {
100  return (m_running) ? (m_totalTime + theTime() - m_startTime) : m_totalTime;
101  }
102 
104 
107  int64_t centiSeconds() const { return milliSeconds()/10; }
108 
110 
114  int64_t seconds() const { return milliSeconds()/1000; }
115 
117 
121  int64_t minutes() const { return seconds()/60; }
122 
124 
128  int64_t hours() const { return seconds()/3600; }
129 
130 
132  bool exceeds(int64_t maxSeconds) const {
133  return seconds() >= maxSeconds;
134  }
135 
137 
140  void addCentiSeconds(int64_t centiSeconds) {
141  m_totalTime += 10*centiSeconds;
142  }
143 
144 
146 
151  friend OGDF_EXPORT ostream& operator<<(ostream& os, const Stopwatch &stopwatch);
152 
153 protected:
154 
156 
162  virtual int64_t theTime() const = 0;
163 
164 };
165 
166 
169 public:
171 
176 
178 
184  explicit StopwatchCPU(int64_t milliSecs) : Stopwatch(milliSecs) { }
185 
186  virtual ~StopwatchCPU() { }
187 
188 private:
190  virtual int64_t theTime() const override;
191 };
192 
193 
196 public:
198 
203 
205 
211  explicit StopwatchWallClock(int64_t milliSecs) : Stopwatch(milliSecs) { }
212 
213  virtual ~StopwatchWallClock() { }
214 
215 private:
217  virtual int64_t theTime() const override;
218 };
219 
220 }
StopwatchWallClock(int64_t milliSecs)
Creates a stopwatch for measuring wall-clock time and sets its total time to milliSecs.
Definition: Stopwatch.h:211
virtual ~StopwatchCPU()
Definition: Stopwatch.h:186
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
bool m_running
true, if the timer is running.
Definition: Stopwatch.h:47
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition: Stopwatch.h:121
StopwatchWallClock()
Creates a stopwatch for measuring wall-clock time with total time 0.
Definition: Stopwatch.h:202
StopwatchCPU(int64_t milliSecs)
Creates a stopwatch for measuring CPU time and sets its total time to milliSecs.
Definition: Stopwatch.h:184
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition: Stopwatch.h:107
virtual ~StopwatchWallClock()
Definition: Stopwatch.h:213
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:764
bool exceeds(int64_t maxSeconds) const
Returns true iff the currently elapsed time exceeds maxSeconds.
Definition: Stopwatch.h:132
Stopwatch(int64_t milliSecs)
Initializes a stopwatch and sets its total time to milliSecs.
Definition: Stopwatch.h:64
int64_t m_totalTime
The total time in milliseconds.
Definition: Stopwatch.h:46
Stopwatch()
Initializes a stop watch with total time 0.
Definition: Stopwatch.h:55
Implements a stopwatch measuring wall-clock time.
Definition: Stopwatch.h:195
StopwatchCPU()
Creates a stopwatch for measuring CPU time with total time 0.
Definition: Stopwatch.h:175
int64_t milliSeconds() const
Returns the currently elapsed time in milliseconds.
Definition: Stopwatch.h:99
bool running() const
Returns true if the stopwatch is running, false otherwise.
Definition: Stopwatch.h:92
Basic declarations, included by all source files.
void addCentiSeconds(int64_t centiSeconds)
Adds centiSeconds to total time.
Definition: Stopwatch.h:140
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition: Stopwatch.h:114
int64_t hours() const
Returns the currently elapsed time in hours.
Definition: Stopwatch.h:128
The namespace for all OGDF objects.
virtual ~Stopwatch()
Definition: Stopwatch.h:67
void reset()
Stops the stopwatch and sets its total time to 0.
Definition: Stopwatch.h:85
int64_t m_startTime
The start time of the timer in milliseconds.
Definition: Stopwatch.h:45
Realizes a stopwatch for measuring elapsed time.
Definition: Stopwatch.h:43
Implements a stopwatch measuring CPU time.
Definition: Stopwatch.h:168