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}%)";
212 std::shared_ptr<spdlog::logger>
logger,
213 spdlog::level::level_enum level = spdlog::level::level_enum::info,
232 [[nodiscard]] std::ostream&
ostream()
const;
239 [[nodiscard]]
const std::shared_ptr<spdlog::logger>&
logger()
const;
263 [[nodiscard]] std::
string Format(
271 std::variant<std::
ostream*, std::pair<std::shared_ptr<spdlog::
logger>,
272 spdlog::level::level_enum>>
std::variant< std::ostream *, std::pair< std::shared_ptr< spdlog::logger >, spdlog::level::level_enum > > output_
AutoTimer(const AutoTimer &)=default
std::string Format(std::string_view format=Timer::kDefaultFormat) const
Return the number of elapsed seconds of the wall clock time, user time and system time as a formatted...
AutoTimer & operator=(const AutoTimer &)=default
AutoTimer(std::string format=Timer::kDefaultFormat)
Create a new AutoTimer that will report time measurements to std::cout when destructed.
const std::shared_ptr< spdlog::logger > & logger() const
Retrieve the logger that was passed in the constructor.
AutoTimer & operator=(AutoTimer &&)=default
const std::string & FormatString() const
Retrieve the format string that was passed in the constructor.
std::ostream & ostream() const
Retrieve the output stream object that was passed in the constructor.
AutoTimer(AutoTimer &&)=default
void Report()
Report time (wall, user, system) since construction of AutoTimer() to either a std::ostream or spdlog...
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.