Euclid
Geometry Processing and Shape Analysis in C++
Timer.h
1 
6 #pragma once
7 
8 #include <chrono>
9 
10 namespace Euclid
11 {
17 class Timer
18 {
19 public:
24  void tick()
25  {
26  _started = true;
27  _start = std::chrono::high_resolution_clock::now();
28  }
29 
43  template<typename Rep = double, typename Period = std::ratio<1>>
44  Rep tock()
45  {
46  auto t = std::chrono::high_resolution_clock::now();
47  if (!_started) {
48  return Rep(0);
49  }
50  else {
51  _started = false;
52  return std::chrono::duration_cast<
53  std::chrono::duration<Rep, Period>>(t - _start)
54  .count();
55  }
56  }
57 
58 private:
59  bool _started = false;
60  std::chrono::time_point<std::chrono::high_resolution_clock> _start;
61 };
62 
64 } // namespace Euclid
void tick()
Start the timer.
Definition: Timer.h:24
A simple timer.
Definition: Timer.h:17
Rep tock()
Stop the timer and return the elapsed time.
Definition: Timer.h:44
Definition: AABB.h:6