Dynalib Utils
Stopwatch.h
Go to the documentation of this file.
1 //
2 // Created by Ken Kopelson on 8/10/17.
3 //
4 
5 #ifndef STOPWATCH_H
6 #define STOPWATCH_H
7 
8 #include <string>
9 #include <chrono>
10 
11 using namespace std;
12 using namespace std::chrono;
13 
14 class Stopwatch {
15  bool _useHighRes = false;
16  long _startTime = -1;
17  long _stopTime = -1;
18  long _restartTime = -1;
19  long _totalPaused = 0;
20  long _intervalTime = -1;
21  bool _running = false;
22 
23  long _getNow();
24 
25 public:
26  explicit Stopwatch(bool useHighRes=false);
27 
28  Stopwatch* start();
29  Stopwatch* stop();
30  Stopwatch* restart();
31  long getElapsedTime();
32  long getLastInterval();
33  Stopwatch* reset();
34 
35  long getStartTime() { return _startTime; }
36  long getStopTime() { return _stopTime; }
37  long getTotalPaused() { return _totalPaused; }
38  bool isRunning() { return _running; }
39 
40  string toString(string msg);
41  string toString();
42  void printMessage(string msg);
43  void printMessage();
44 };
45 
46 
47 #endif //STOPWATCH_H
long getStopTime()
Definition: Stopwatch.h:36
long getStartTime()
Definition: Stopwatch.h:35
Definition: Stopwatch.h:14
bool isRunning()
Definition: Stopwatch.h:38
long getTotalPaused()
Definition: Stopwatch.h:37