The spica renderer
timer.h
1 #ifndef _SPICA_TIMER_H_
2 #define _SPICA_TIMER_H_
3 
4 #if __cplusplus > 199711L
5 #include <chrono>
6 typedef std::chrono::time_point<std::chrono::system_clock> time_type;
7 inline time_type tick() {
8  return std::chrono::system_clock::now();
9 }
10 inline double to_duration(time_type start, time_type end) {
11  return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000.0;
12 }
13 #else
14 #include <ctime>
15 typedef clock_t time_type;
16 inline time_type tick() {
17  return clock();
18 }
19 inline double to_duration(time_type start, time_type end) {
20  return (end - start) / 1000.0;
21 }
22 #endif
23 
24 namespace spica {
25 
26  class Timer {
27  private:
28  time_type _start;
29  time_type _end;
30 
31  public:
32  Timer()
33  : _start()
34  , _end()
35  {
36  }
37 
38  void start() {
39  _start = tick();
40  }
41 
42  double stop() {
43  _end = tick();
44  return to_duration(_start, _end);
45  }
46  };
47 }
48 
49 #endif // _SPICA_TIMER_H_
Definition: timer.h:26