aGrUM  0.16.0
gum::Timer Class Reference

Class used to compute response times for benchmark purposesThis class represents a classic timer, it starts in the constructor, you can reset it with method reset() and you can get the delta time with the method step(). More...

#include <agrum/core/timer.h>

+ Collaboration diagram for gum::Timer:

Public Member Functions

Constructors / Destructors
 Timer ()
 Default constructor (launching the timer). More...
 
 Timer (const Timer &timer)
 Copy constructor. More...
 
 ~Timer ()
 Destructor. More...
 
Operators
Timeroperator= (const Timer &timer)
 Copy operator. More...
 
Timer manipulation
void reset ()
 Reset the timer. More...
 
double pause ()
 Pause the timer and return the delta (. More...
 
double resume ()
 Resume the timer and return the delta (. More...
 
double step () const
 Returns the delta time between now and the last reset() call (or the constructor). More...
 

Protected Attributes

std::chrono::high_resolution_clock::time_point _start
 Time of the last call to reset() or the constructor. More...
 
std::chrono::high_resolution_clock::time_point _pause
 Time of the last call to pause(). More...
 
bool _sleeping
 False if running. More...
 

Detailed Description

Class used to compute response times for benchmark purposes

This class represents a classic timer, it starts in the constructor, you can reset it with method reset() and you can get the delta time with the method step().

This class uses double for representing time data, all the values are in seconds, and the precision is about 0.001 s

Definition at line 51 of file timer.h.

Constructor & Destructor Documentation

◆ Timer() [1/2]

gum::Timer::Timer ( )

Default constructor (launching the timer).

Definition at line 38 of file timer.cpp.

References reset().

38  {
39  GUM_CONSTRUCTOR(Timer);
40  reset();
41  }
void reset()
Reset the timer.
Definition: timer_inl.h:32
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:38
+ Here is the call graph for this function:

◆ Timer() [2/2]

gum::Timer::Timer ( const Timer timer)

Copy constructor.

Parameters
timerThe gum::Timer to copy.

Definition at line 43 of file timer.cpp.

43  :
44  _start(from._start), _pause(from._pause), _sleeping(from._sleeping) {
45  GUM_CONS_CPY(Timer);
46  }
std::chrono::high_resolution_clock::time_point _pause
Time of the last call to pause().
Definition: timer.h:122
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:38
bool _sleeping
False if running.
Definition: timer.h:125
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:119

◆ ~Timer()

gum::Timer::~Timer ( )

Destructor.

Definition at line 48 of file timer.cpp.

48 { GUM_DESTRUCTOR(Timer); }
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:38

Member Function Documentation

◆ operator=()

Timer & gum::Timer::operator= ( const Timer timer)

Copy operator.

Parameters
timerThe gum::Timer to copy.

Definition at line 50 of file timer.cpp.

References _pause, _sleeping, and _start.

50  {
51  GUM_OP_CPY(Timer);
52  _start = from._start;
53  _pause = from._pause;
54  _sleeping = from._sleeping;
55  return *this;
56  }
std::chrono::high_resolution_clock::time_point _pause
Time of the last call to pause().
Definition: timer.h:122
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:38
bool _sleeping
False if running.
Definition: timer.h:125
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:119

◆ pause()

INLINE double gum::Timer::pause ( )

Pause the timer and return the delta (.

See also
gum::Timer::step() ). Returns the delta (
gum::Timer::step() ).

Definition at line 53 of file timer_inl.h.

References _pause, _sleeping, and step().

Referenced by gum::ApproximationScheme::_stopScheme().

53  {
54  if (!_sleeping) {
55  _pause = std::chrono::high_resolution_clock::now();
56  _sleeping = true;
57  }
58 
59  return step();
60  }
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
bool _sleeping
False if running.
Definition: timer.h:125
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

INLINE void gum::Timer::reset ( )

Reset the timer.

Definition at line 32 of file timer_inl.h.

References _pause, _sleeping, and _start.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__buildReduceGraph(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::ApproximationScheme::initApproximationScheme(), gum::learning::Miic::learnMixedStructure(), gum::prm::o3prmr::O3prmrInterpreter::query(), and Timer().

32  {
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  }
std::chrono::high_resolution_clock::time_point _pause
Time of the last call to pause().
Definition: timer.h:122
bool _sleeping
False if running.
Definition: timer.h:125
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:119
+ Here is the caller graph for this function:

◆ resume()

INLINE double gum::Timer::resume ( )

Resume the timer and return the delta (.

See also
gum::Timer::step() ). Returns the delta (
gum::Timer::step() ).

Definition at line 63 of file timer_inl.h.

References _pause, _sleeping, _start, and step().

63  {
64  if (_sleeping) {
65  _start += std::chrono::high_resolution_clock::now() - _pause;
66  _sleeping = false;
67  }
68 
69  return step();
70  }
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
bool _sleeping
False if running.
Definition: timer.h:125
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:119
+ Here is the call graph for this function:

◆ step()

INLINE double gum::Timer::step ( ) const

Returns the delta time between now and the last reset() call (or the constructor).

Returns
Returns the delta time in seconds (accuracy : 0.001 ms).

Definition at line 42 of file timer_inl.h.

References _pause, _sleeping, and _start.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__buildReduceGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__reducePattern(), gum::learning::Miic::_initiation(), gum::learning::Miic::_iteration(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::ApproximationScheme::continueApproximationScheme(), gum::ApproximationScheme::currentTime(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), pause(), gum::prm::o3prmr::O3prmrInterpreter::query(), and resume().

42  {
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  }
std::chrono::high_resolution_clock::time_point _pause
Time of the last call to pause().
Definition: timer.h:122
bool _sleeping
False if running.
Definition: timer.h:125
std::chrono::high_resolution_clock::time_point _start
Time of the last call to reset() or the constructor.
Definition: timer.h:119
+ Here is the caller graph for this function:

Member Data Documentation

◆ _pause

std::chrono::high_resolution_clock::time_point gum::Timer::_pause
protected

Time of the last call to pause().

Definition at line 122 of file timer.h.

Referenced by operator=(), pause(), reset(), resume(), and step().

◆ _sleeping

bool gum::Timer::_sleeping
protected

False if running.

Definition at line 125 of file timer.h.

Referenced by operator=(), pause(), reset(), resume(), and step().

◆ _start

std::chrono::high_resolution_clock::time_point gum::Timer::_start
protected

Time of the last call to reset() or the constructor.

Definition at line 119 of file timer.h.

Referenced by operator=(), reset(), resume(), and step().


The documentation for this class was generated from the following files: