dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
dlinear::TimerGuard Class Reference

The TimeGuard wraps a timer object and pauses it when the guard object is destructed. More...

#include <Timer.h>

Public Member Functions

 TimerGuard (Timer *timer, bool enabled, bool start_timer=true)
 Construct a new TimeGuard object.
 
 ~TimerGuard ()
 When the timer guard object is destructed, it pauses the embedded timer object.
 
void Pause ()
 Pause the guarded timer object.
 
void Resume ()
 Resume the guarded timer object.
 

Private Attributes

Timer *const timer_
 The timer to be guarded.
 
const bool enabled_ {false}
 Whether the timer is enabled.
 

Detailed Description

The TimeGuard wraps a timer object and pauses it when the guard object is destructed.

Useful for measuring the exact time spent in a block of code.

// Example usage
class MyClass {
private:
Timer timer_;
public:
void function_to_measure() {
TimerGuard guard(&timer_, true);
// Code to measure
}
// Return the total time elapsed, even across multiple calls
double time_elapsed() { return timer_.seconds(); }
};
std::chrono::duration< double >::rep seconds() const
Get read-only access to the number elapsed seconds of the timer.
Definition Timer.cpp:56
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
Definition Timer.h:129
Timer class using the a steady clock.
Definition Timer.h:95

Definition at line 129 of file Timer.h.

Constructor & Destructor Documentation

◆ TimerGuard()

dlinear::TimerGuard::TimerGuard ( Timer * timer,
bool enabled,
bool start_timer = true )

Construct a new TimeGuard object.

If enabled is false or timer is a nullptr, this class does not do anything. If start_timer is true, starts the timer in the constructor. Otherwise, it does not start it and a user has to call Resume() to start it.

Parameters
timera pointer to the timer object to be guarded
enabledwhether the timer is enabled and should run
start_timerwhether the timer should be started as soon as the guard is created

Definition at line 72 of file Timer.cpp.

◆ ~TimerGuard()

dlinear::TimerGuard::~TimerGuard ( )

When the timer guard object is destructed, it pauses the embedded timer object.

If the timer is not enabled, this function does nothing.

Definition at line 77 of file Timer.cpp.


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