Loading...
Searching...
No Matches
gpr::WallClockLimit Class Reference

#include <gpr/ml/PhaseTimers.h>

Public Types

using Clock = std::chrono::steady_clock
using Now = std::function<Clock::time_point()>

Public Member Functions

 WallClockLimit (double seconds, Now now={})
bool enabled () const noexcept
double elapsedSeconds () const
bool reached () const
double seconds () const noexcept

Detailed Description

A monotonic wall-clock deadline shared by a complete search and every nested phase. The optional clock makes deadline behaviour testable without sleeping; production uses steady_clock.

Definition at line 25 of file PhaseTimers.h.

Member Typedef Documentation

◆ Clock

using gpr::WallClockLimit::Clock = std::chrono::steady_clock

Definition at line 27 of file PhaseTimers.h.

◆ Now

using gpr::WallClockLimit::Now = std::function<Clock::time_point()>

Definition at line 28 of file PhaseTimers.h.

Constructor & Destructor Documentation

◆ WallClockLimit()

gpr::WallClockLimit::WallClockLimit ( double seconds,
Now now = {} )
inlineexplicit

Definition at line 30 of file PhaseTimers.h.

30 {})
31 : seconds_(seconds),
32 now_(now ? std::move(now) : Now{[] { return Clock::now(); }}),
33 start_(now_())
34 {
35 }
double seconds() const noexcept
Definition PhaseTimers.h:52
std::function< Clock::time_point()> Now
Definition PhaseTimers.h:28

Member Function Documentation

◆ elapsedSeconds()

double gpr::WallClockLimit::elapsedSeconds ( ) const
inlinenodiscard

Definition at line 42 of file PhaseTimers.h.

43 {
44 return std::chrono::duration<double>(now_() - start_).count();
45 }

◆ enabled()

bool gpr::WallClockLimit::enabled ( ) const
inlinenodiscardnoexcept

Definition at line 37 of file PhaseTimers.h.

38 {
39 return seconds_ > 0.0 && std::isfinite(seconds_);
40 }

◆ reached()

bool gpr::WallClockLimit::reached ( ) const
inlinenodiscard

Definition at line 47 of file PhaseTimers.h.

48 {
49 return enabled() && elapsedSeconds() >= seconds_;
50 }
double elapsedSeconds() const
Definition PhaseTimers.h:42
bool enabled() const noexcept
Definition PhaseTimers.h:37

◆ seconds()

double gpr::WallClockLimit::seconds ( ) const
inlinenodiscardnoexcept

Definition at line 52 of file PhaseTimers.h.

53 {
54 return seconds_;
55 }

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