Measures elapsed wall-clock time from construction.
More...
|
| | timer_t (std::string title="Timer", time_print_t time_print=simple) |
| | Starts a timer.
|
| template<std::invocable F> |
| auto | time_it (F &&f, double target_time=1.0) -> std::string |
| | Repeatedly invokes f until target_time has elapsed.
|
| auto | make_time_str () const -> std::string |
| | Formats the time elapsed since construction, divided by the cycle count.
|
| auto | make_time_str (double time) const -> std::string |
| | Formats a duration, choosing a unit that keeps the value readable.
|
| auto | to_string () const -> std::string |
| | Renders the measurement through the configured print callable.
|
| auto | operator/ (std::size_t val) -> timer_t & |
| | Sets the divisor applied to the measured interval.
|
|
| static auto | simple (std::string title, std::string time) -> std::string |
| | Renders a measurement as "title: time".
|
| static auto | big (std::string title, std::string time) -> std::string |
| | Renders a measurement inside a full-width banner.
|
|
| using | clock_t = std::chrono::steady_clock |
| | The clock used for all measurements.
|
|
using | time_point_t = std::chrono::time_point<clock_t> |
| | A point in time as reported by clock_t.
|
|
using | time_print_t = std::function<std::string(std::string, std::string)> |
| | Renders a finished measurement given a title and a formatted duration.
|
|
|
std::string | title_ |
| | Label reported alongside the measurement.
|
|
time_print_t | time_print_ |
| | Callable used to render the finished measurement.
|
|
time_point_t | start_ |
| | The instant this timer started measuring.
|
|
std::size_t | cycles_ {1} |
| | Number of cycles the measured interval is divided by.
|
Measures elapsed wall-clock time from construction.
The timer starts when it is constructed. to_string renders the time elapsed since then, divided by the cycle count set through operator/.
◆ clock_t
The clock used for all measurements.
- Note
- This member alias shadows std::clock_t inside the class body. Nothing here refers to the C library type, so the shadowing is harmless, but qualify as std::clock_t if you ever need it.
◆ timer_t()
Starts a timer.
- Parameters
-
| title | Label reported alongside the measurement. |
| time_print | Callable used to render the finished measurement. |
◆ big()
| auto cli::timer_t::big |
( |
std::string | title, |
|
|
std::string | time ) -> std::string |
|
inlinestaticnodiscard |
Renders a measurement inside a full-width banner.
- Parameters
-
| title | Label for the measurement. |
| time | Preformatted duration. |
- Returns
- The rendered multi-line measurement.
◆ make_time_str() [1/2]
| auto cli::timer_t::make_time_str |
( |
| ) |
const -> std::string |
|
inlinenodiscard |
Formats the time elapsed since construction, divided by the cycle count.
- Returns
- The elapsed time with an automatically chosen unit.
◆ make_time_str() [2/2]
| auto cli::timer_t::make_time_str |
( |
double | time | ) |
const -> std::string |
|
inlinenodiscard |
Formats a duration, choosing a unit that keeps the value readable.
- Parameters
-
| time | A duration in seconds. |
- Returns
- The duration rendered to five significant digits, with a unit.
◆ operator/()
| auto cli::timer_t::operator/ |
( |
std::size_t | val | ) |
-> timer_t & |
|
inline |
Sets the divisor applied to the measured interval.
- Parameters
-
| val | Number of cycles the interval represents. |
- Returns
- A reference to this timer, for chaining.
◆ simple()
| auto cli::timer_t::simple |
( |
std::string | title, |
|
|
std::string | time ) -> std::string |
|
inlinestaticnodiscard |
Renders a measurement as "title: time".
- Parameters
-
| title | Label for the measurement. |
| time | Preformatted duration. |
- Returns
- The rendered single-line measurement.
◆ time_it()
template<std::invocable F>
| auto cli::timer_t::time_it |
( |
F && | f, |
|
|
double | target_time = 1.0 ) -> std::string |
|
inlinenodiscard |
Repeatedly invokes f until target_time has elapsed.
Runs f at least once and at most 100 times, stopping early once the accumulated time reaches target_time. The timer's own start point is restored before returning, so calling this does not disturb to_string.
- Template Parameters
-
| F | Any callable invocable with no arguments. |
- Parameters
-
| f | The callable to time. |
| target_time | Seconds to keep repeating for. |
- Returns
- A description of the mean time per call and the number of calls.
◆ to_string()
| auto cli::timer_t::to_string |
( |
| ) |
const -> std::string |
|
inlinenodiscard |
Renders the measurement through the configured print callable.
- Returns
- The fully rendered measurement.
The documentation for this class was generated from the following file:
- /home/mccakit/desktop/repositories/cli11/src/timer.cpp