19 template <
typename Time = std::chrono::milliseconds,
typename Clock = std::chrono::high_resolution_clock>
22 mutable std::mutex mtx;
23 Clock::time_point start_time;
24 Clock::time_point end_time;
27 explicit progress() : start_time(Clock::now()), end_time(start_time)
39 template <
typename F,
typename... Args,
typename Duration = Time>
45 if constexpr (std::is_void_v<std::invoke_result_t<std::decay_t<F>, std::decay_t<Args>...>>)
47 std::invoke(std::forward<F>(f), std::forward<Args>(
args)...);
51 const auto result = std::invoke(std::forward<F>(f), std::forward<Args>(
args)...);
54 return Duration::zero();
65 std::lock_guard<std::mutex> lock(this->mtx);
66 start_time = end_time = Clock::now();
78 template <
typename T =
double>
81 std::lock_guard<std::mutex> lock(this->mtx);
82 end_time = Clock::now();
83 return static_cast<T
>(std::chrono::duration_cast<Time>(end_time - start_time).count());
86 static double to_double_from_duration(
const std::chrono::duration<double> &
duration)
noexcept
Command-line argument handler with JSON support.
Definition args.h:19
void start() noexcept
Start the progress.
Definition progress.h:63
static Duration duration(F &&f, Args &&...args)
Measures the duration of a callable object.
Definition progress.h:40
T elapsed() noexcept
Capture the elapsed time.
Definition progress.h:79
void reset() noexcept
Reset the progress.
Definition progress.h:70