38#ifndef INCG_529e391f2915453388028b848b3dcbd6
39#define INCG_529e391f2915453388028b848b3dcbd6
41#include <spdlog/logger.h>
77 std::chrono::nanoseconds
wall;
85 std::chrono::nanoseconds
user;
106 cpu_times{std::chrono::nanoseconds(0), std::chrono::nanoseconds(0),
107 std::chrono::nanoseconds(0)};
120 [[nodiscard]] cpu_times
Elapsed() const noexcept;
141 [[nodiscard]] std::
string Format(
148 void Start() noexcept;
153 void Stop() noexcept;
165 "{w:.6}s wall, {u:.6}s user + {s:.6}s system = {t:.6}s CPU ({p:.3}%)
";
190 explicit AutoTimer(std::string format = Timer::kDefaultFormat);
199 explicit AutoTimer(std::ostream& stream,
200 std::string format = Timer::kDefaultFormat);
212 std::shared_ptr<spdlog::logger> logger,
213 spdlog::level::level_enum level = spdlog::level::level_enum::info,
214 std::string format = Timer::kDefaultFormat);
216 AutoTimer(const AutoTimer&) = default;
217 AutoTimer(AutoTimer&&) = default;
218 AutoTimer& operator=(const AutoTimer&) = default;
219 AutoTimer& operator=(AutoTimer&&) = default;
232 [[nodiscard]] std::ostream& ostream() const;
239 [[nodiscard]] const std::shared_ptr<spdlog::logger>& logger() const;
244 [[nodiscard]] const std::string& FormatString() const;
260 [[nodiscard]] Timer::cpu_times Elapsed() const noexcept;
263 [[nodiscard]] std::string Format(
264 std::string_view format = Timer::kDefaultFormat) const;
270 // ostream is stored as pointer so assignment operator works.
271 std::variant<std::ostream*, std::pair<std::shared_ptr<spdlog::logger>,
272 spdlog::level::level_enum>>
276} // namespace lf::base
278#endif // INCG_529e391f2915453388028b848b3dcbd6
Timer class to measure time.
std::string Format(std::string_view format=kDefaultFormat) const
Return the number of elapsed seconds of the wall clock time, user time and system time as a formatted...
void Stop() noexcept
stop the timer, stop counting the elapsed time.
void Resume() noexcept
Resume the timer, i.e. start counting from where we stopped the last time.
cpu_times Elapsed() const noexcept
Elapsed time since timer start, doesn't stop the timer.
static std::string kDefaultFormat
Default format string that is used by Format()
bool IsStopped() const noexcept
Is the timer currently stopped?
Timer(bool start=true) noexcept
Construct a new timer and optionally start it immediately.
void Start() noexcept
(Re)starts the timer, i.e. the timer starts counting from 0 when this method is called.
Contains basic functionality that is used by other parts of LehrFEM++.
Packages the elapsed wall clock time, user process CPU time, and system process CPU time.
std::chrono::nanoseconds system
Elapsed System time in nano-seconds.
std::chrono::nanoseconds user
Elapsed User time in nano-seconds.
std::chrono::nanoseconds wall
Elapsed WallClock time in nano-seconds.