16 template <
typename Time = std::chrono::microseconds,
typename Clock = std::chrono::high_resolution_clock>
19 mutable std::mutex mtx;
20 Clock::time_point start_time;
21 Clock::time_point end_time;
24 explicit progress() : start_time(Clock::now()), end_time(start_time)
36 template <
typename F,
typename... Args,
typename Duration = Time>
42 if constexpr (std::is_void_v<std::invoke_result_t<F, Args...>>)
44 std::invoke(std::forward<F>(f), std::forward<Args>(
args)...);
48 auto result = std::invoke(std::forward<F>(f), std::forward<Args>(
args)...);
51 return Duration::zero();
62 std::lock_guard<std::mutex> lock(this->mtx);
63 start_time = end_time = Clock::now();
75 template <
typename T =
double>
78 std::lock_guard<std::mutex> lock(this->mtx);
79 end_time = Clock::now();
80 return static_cast<T
>(std::chrono::duration_cast<Time>(end_time - start_time).count());
Command-line argument handler with JSON support.
Definition args.h:19
Simple clock for elapsed events.
Definition progress.h:18
void start() noexcept
Start the progress.
Definition progress.h:60
T elapsed() noexcept
Capture the elapsed time.
Definition progress.h:76
static Duration duration(F &&f, Args &&... args)
Measures the duration of a callable object.
Definition progress.h:37
void reset() noexcept
Reset the progress.
Definition progress.h:67