aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::Timer Class Reference

Class used to compute response times for benchmark purposes. More...

#include <agrum/base/core/timer.h>

Collaboration diagram for gum::Timer:

Public Member Functions

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

Protected Member Functions

std::chrono::duration< double, std::milli > step_ () const

Protected Attributes

std::chrono::high_resolution_clock::time_point start_
 Time of the last call to reset() or the constructor.
std::chrono::high_resolution_clock::time_point pause_
 Time of the last call to pause().
bool sleeping_
 False if running.

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

Constructor & Destructor Documentation

◆ Timer() [1/2]

gum::Timer::Timer ( )

Default constructor (launching the timer).

Definition at line 61 of file timer.cpp.

61 {
62 GUM_CONSTRUCTOR(Timer);
63 reset();
64 }
void reset()
Reset the timer.
Definition timer_inl.h:52
Timer()
Default constructor (launching the timer).
Definition timer.cpp:61

References Timer(), and reset().

Referenced by Timer(), Timer(), ~Timer(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Timer() [2/2]

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

Copy constructor.

Parameters
timerThe gum::Timer to copy.

Definition at line 66 of file timer.cpp.

66 :
67 start_(from.start_), pause_(from.pause_), sleeping_(from.sleeping_) {
68 GUM_CONS_CPY(Timer);
69 }
bool sleeping_
False if running.
Definition timer.h:152
std::chrono::high_resolution_clock::time_point pause_
Time of the last call to pause().
Definition timer.h:149
std::chrono::high_resolution_clock::time_point start_
Time of the last call to reset() or the constructor.
Definition timer.h:146

References Timer(), pause_, sleeping_, and start_.

Here is the call graph for this function:

◆ ~Timer()

gum::Timer::~Timer ( )

Destructor.

Definition at line 71 of file timer.cpp.

71 {
72 GUM_DESTRUCTOR(Timer);
73 ;
74 }

References Timer().

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 76 of file timer.cpp.

76 {
77 GUM_OP_CPY(Timer);
78 start_ = from.start_;
79 pause_ = from.pause_;
80 sleeping_ = from.sleeping_;
81 return *this;
82 }

References Timer(), pause_, sleeping_, and start_.

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 (

See also
gum::Timer::step() ).

Definition at line 74 of file timer_inl.h.

74 {
75 if (!sleeping_) {
76 pause_ = std::chrono::high_resolution_clock::now();
77 sleeping_ = true;
78 }
79
80 return step();
81 }
double step() const
Returns the delta time between now and the last reset() call (or the constructor).
Definition timer_inl.h:71

References pause_, sleeping_, and step().

Here is the call graph for this function:

◆ reset()

INLINE void gum::Timer::reset ( )

Reset the timer.

Definition at line 52 of file timer_inl.h.

52 {
53 sleeping_ = false;
54 start_ = std::chrono::high_resolution_clock::now();
55 pause_ = std::chrono::high_resolution_clock::now();
56
57 // do start_ = clock(); while ( start_ == k );// to be sure to start at the
58 // beginning of a tick
59 }

References pause_, sleeping_, and start_.

Referenced by Timer(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), and gum::prm::o3prmr::O3prmrInterpreter::query().

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 (

See also
gum::Timer::step() ).

Definition at line 84 of file timer_inl.h.

84 {
85 if (sleeping_) {
86 start_ += std::chrono::high_resolution_clock::now() - pause_;
87 sleeping_ = false;
88 }
89
90 return step();
91 }

References pause_, sleeping_, start_, and step().

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

71{ return step_().count() / 1000.0; }
std::chrono::duration< double, std::milli > step_() const
Definition timer_inl.h:62

References step_().

Referenced by gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), pause(), gum::prm::o3prmr::O3prmrInterpreter::query(), resume(), and toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ step_()

INLINE std::chrono::duration< double, std::milli > gum::Timer::step_ ( ) const
protected

Definition at line 62 of file timer_inl.h.

62 {
63 std::chrono::duration< double, std::milli > ms;
64 if (sleeping_) ms = pause_ - start_;
65 else ms = std::chrono::high_resolution_clock::now() - start_;
66
67 return ms;
68 }

References pause_, sleeping_, and start_.

Referenced by step().

Here is the caller graph for this function:

◆ toString()

std::string gum::Timer::toString ( ) const

Returns the delta time between now and the last reset() in a human format.

Returns
a string representing the delta time

Definition at line 84 of file timer.cpp.

84 {
85 auto d = step();
86 auto sec = fmod(d, 60);
87 d = (d - sec) / 60;
88 auto minut = fmod(d, 60);
89 d = (d - minut) / 60;
90
91 std::stringstream s;
92 s << std::setfill('0') << std::setw(2) << int(d) << ":";
93 s << std::setfill('0') << std::setw(2) << int(minut) << ":";
94 s << ((sec < 10) ? "0" : "") << sec;
95
96 return s.str();
97 }

References step().

Referenced by gum::operator<<().

Here is the call graph for this function:
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 149 of file timer.h.

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

◆ sleeping_

bool gum::Timer::sleeping_
protected

False if running.

Definition at line 152 of file timer.h.

Referenced by Timer(), 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 146 of file timer.h.

Referenced by Timer(), operator=(), reset(), resume(), and step_().


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