aGrUM  0.14.2
timer_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 // to ease IDE parser
21 #include <chrono>
22 
23 #include <agrum/core/timer.h>
24 
25 namespace gum {
26 
27 
28  INLINE
29  void Timer::reset() {
30  _sleeping = false;
31  _start = std::chrono::high_resolution_clock::now();
32  _pause = std::chrono::high_resolution_clock::now();
33 
34  // do _start = clock(); while ( _start == k );// to be sure to start at the
35  // beginning of a tick
36  }
37 
38  INLINE
39  double Timer::step() const {
40  std::chrono::duration< double, std::milli > ms;
41  ;
42  if (_sleeping)
43  ms = _pause - _start;
44  else
45  ms = std::chrono::high_resolution_clock::now() - _start;
46  return ms.count() / 1000.0;
47  }
48 
49  INLINE
50  double Timer::pause() {
51  if (!_sleeping) {
52  _pause = std::chrono::high_resolution_clock::now();
53  _sleeping = true;
54  }
55 
56  return step();
57  }
58 
59  INLINE
60  double Timer::resume() {
61  if (_sleeping) {
62  _start += std::chrono::high_resolution_clock::now() - _pause;
63  _sleeping = false;
64  }
65 
66  return step();
67  }
68 } /* namespace gum */
std::chrono::high_resolution_clock::time_point _pause
Time of the last call to pause().
Definition: timer.h:119
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:39
Class used to compute response times for benchmark purposes.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void reset()
Reset the timer.
Definition: timer_inl.h:29
double pause()
Pause the timer and return the delta (.
Definition: timer_inl.h:50
bool _sleeping
False if running.
Definition: timer.h:122
double resume()
Resume the timer and return the delta (.
Definition: timer_inl.h:60
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:116