aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
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/tools/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 50 of file timer.h.

Constructor & Destructor Documentation

◆ Timer() [1/2]

gum::Timer::Timer ( )

Default constructor (launching the timer).

Definition at line 37 of file timer.cpp.

References gum::Set< Key, Alloc >::emplace().

37  {
38  GUM_CONSTRUCTOR(Timer);
39  reset();
40  }
void reset()
Reset the timer.
Definition: timer_inl.h:31
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:37
+ 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 42 of file timer.cpp.

References gum::Set< Key, Alloc >::emplace().

42  :
43  start_(from.start_), pause_(from.pause_), sleeping_(from.sleeping_) {
44  GUM_CONS_CPY(Timer);
45  }
std::chrono::high_resolution_clock::time_point start_
Time of the last call to reset() or the constructor.
Definition: timer.h:118
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:37
bool sleeping_
False if running.
Definition: timer.h:124
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition: timer.h:121
+ Here is the call graph for this function:

◆ ~Timer()

gum::Timer::~Timer ( )

Destructor.

Definition at line 47 of file timer.cpp.

References gum::Set< Key, Alloc >::emplace().

47  {
48  GUM_DESTRUCTOR(Timer);
49  ;
50  }
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:37
+ Here is the call graph for this function:

Member Function Documentation

◆ operator=()

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

Copy operator.

Parameters
timerThe gum::Timer to copy.

Definition at line 52 of file timer.cpp.

References gum::Set< Key, Alloc >::emplace().

52  {
53  GUM_OP_CPY(Timer);
54  start_ = from.start_;
55  pause_ = from.pause_;
56  sleeping_ = from.sleeping_;
57  return *this;
58  }
std::chrono::high_resolution_clock::time_point start_
Time of the last call to reset() or the constructor.
Definition: timer.h:118
Timer()
Default constructor (launching the timer).
Definition: timer.cpp:37
bool sleeping_
False if running.
Definition: timer.h:124
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition: timer.h:121
+ Here is the call graph for this function:

◆ 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 52 of file timer_inl.h.

References gum::Set< Key, Alloc >::emplace().

52  {
53  if (!sleeping_) {
54  pause_ = std::chrono::high_resolution_clock::now();
55  sleeping_ = true;
56  }
57 
58  return step();
59  }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:41
bool sleeping_
False if running.
Definition: timer.h:124
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition: timer.h:121
+ Here is the call graph for this function:

◆ reset()

INLINE void gum::Timer::reset ( )

Reset the timer.

Definition at line 31 of file timer_inl.h.

References gum::Set< Key, Alloc >::emplace().

31  {
32  sleeping_ = false;
33  start_ = std::chrono::high_resolution_clock::now();
34  pause_ = std::chrono::high_resolution_clock::now();
35 
36  // do start_ = clock(); while ( start_ == k );// to be sure to start at the
37  // beginning of a tick
38  }
std::chrono::high_resolution_clock::time_point start_
Time of the last call to reset() or the constructor.
Definition: timer.h:118
bool sleeping_
False if running.
Definition: timer.h:124
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition: timer.h:121
+ Here is the call 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 62 of file timer_inl.h.

References gum::Set< Key, Alloc >::emplace().

62  {
63  if (sleeping_) {
64  start_ += std::chrono::high_resolution_clock::now() - pause_;
65  sleeping_ = false;
66  }
67 
68  return step();
69  }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition: timer_inl.h:41
std::chrono::high_resolution_clock::time_point start_
Time of the last call to reset() or the constructor.
Definition: timer.h:118
bool sleeping_
False if running.
Definition: timer.h:124
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition: timer.h:121
+ 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 41 of file timer_inl.h.

References gum::Set< Key, Alloc >::emplace().

41  {
42  std::chrono::duration< double, std::milli > ms;
43  ;
44  if (sleeping_)
45  ms = pause_ - start_;
46  else
47  ms = std::chrono::high_resolution_clock::now() - start_;
48  return ms.count() / 1000.0;
49  }
std::chrono::high_resolution_clock::time_point start_
Time of the last call to reset() or the constructor.
Definition: timer.h:118
bool sleeping_
False if running.
Definition: timer.h:124
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition: timer.h:121
+ Here is the call 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 121 of file timer.h.

◆ sleeping_

bool gum::Timer::sleeping_
protected

False if running.

Definition at line 124 of file timer.h.

◆ 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 118 of file timer.h.


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