emilib
timer.hpp
1 // By Emil Ernerfeldt 2012-2016
2 // LICENSE:
3 // This software is dual-licensed to the public domain and under the following
4 // license: you are granted a perpetual, irrevocable license to copy, modify,
5 // publish, and distribute this file as you see fit.
6 // HISTORY:
7 // Created in 2012-05-26.
8 
9 #pragma once
10 
11 #include <chrono>
12 
13 namespace emilib {
14 
16 class Timer
17 {
18 public:
20  Timer();
21 
23  double reset();
24 
25  double secs() const;
26  unsigned long long nanoseconds() const;
27 
29  void set_secs(double s);
30  void set_nanoseconds(double s);
31 
33  static double seconds_since_startup();
34 
35 private:
36  using Clock = std::chrono::steady_clock; // Always counting up.
37  Clock::time_point _start;
38 };
39 
40 } // namespace emilib
Simple wall-time monotonic clock.
Definition: timer.hpp:16
void set_secs(double s)
Functions for going back or forward in time:
static double seconds_since_startup()
Seconds since start of program.
Timer()
Will start the Timer.
double reset()
Returns seconds since last reset().
Definition: coroutine.hpp:18