Cheetah Software  1.0
Timer.h
Go to the documentation of this file.
1 
5 #ifndef PROJECT_TIMER_H
6 #define PROJECT_TIMER_H
7 
8 #include <assert.h>
9 #include <stdint.h>
10 #include <time.h>
11 
12 class Timer {
13  public:
14  explicit Timer() { start(); }
15 
16  void start() { clock_gettime(CLOCK_MONOTONIC, &_startTime); }
17 
18  double getMs() { return (double)getNs() / 1.e6; }
19 
20  int64_t getNs() {
21  struct timespec now;
22  clock_gettime(CLOCK_MONOTONIC, &now);
23  return (int64_t)(now.tv_nsec - _startTime.tv_nsec) +
24  1000000000 * (now.tv_sec - _startTime.tv_sec);
25  }
26 
27  double getSeconds() { return (double)getNs() / 1.e9; }
28 
29  struct timespec _startTime;
30 };
31 
32 #endif // PROJECT_TIMER_H
Timer()
Definition: Timer.h:14
Definition: Timer.h:12
int64_t getNs()
Definition: Timer.h:20
void start()
Definition: Timer.h:16
double getSeconds()
Definition: Timer.h:27
struct timespec _startTime
Definition: Timer.h:29
double getMs()
Definition: Timer.h:18