aGrUM  0.16.0
timer_inl.h
Go to the documentation of this file.
1 
23 // to ease IDE parser
24 #include <chrono>
25 
26 #include <agrum/core/timer.h>
27 
28 namespace gum {
29 
30 
31  INLINE
32  void Timer::reset() {
33  _sleeping = false;
34  _start = std::chrono::high_resolution_clock::now();
35  _pause = std::chrono::high_resolution_clock::now();
36 
37  // do _start = clock(); while ( _start == k );// to be sure to start at the
38  // beginning of a tick
39  }
40 
41  INLINE
42  double Timer::step() const {
43  std::chrono::duration< double, std::milli > ms;
44  ;
45  if (_sleeping)
46  ms = _pause - _start;
47  else
48  ms = std::chrono::high_resolution_clock::now() - _start;
49  return ms.count() / 1000.0;
50  }
51 
52  INLINE
53  double Timer::pause() {
54  if (!_sleeping) {
55  _pause = std::chrono::high_resolution_clock::now();
56  _sleeping = true;
57  }
58 
59  return step();
60  }
61 
62  INLINE
63  double Timer::resume() {
64  if (_sleeping) {
65  _start += std::chrono::high_resolution_clock::now() - _pause;
66  _sleeping = false;
67  }
68 
69  return step();
70  }
71 } /* namespace gum */
std::chrono::high_resolution_clock::time_point _pause
Time of the last call to pause().
Definition: timer.h:122
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:42
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void reset()
Reset the timer.
Definition: timer_inl.h:32
double pause()
Pause the timer and return the delta (.
Definition: timer_inl.h:53
bool _sleeping
False if running.
Definition: timer.h:125
double resume()
Resume the timer and return the delta (.
Definition: timer_inl.h:63
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:119