![]() |
LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
|
Measures execution time between construction and destruction. AutoTimer can output either to a std::ostream or to a spdlog::logger
More...
#include <lf/base/timer.h>
Public Member Functions | |
| AutoTimer (std::string format=Timer::kDefaultFormat) | |
Create a new AutoTimer that will report time measurements to std::cout when destructed. | |
| AutoTimer (std::ostream &stream, std::string format=Timer::kDefaultFormat) | |
| Create a new AutoTimer that will report to the given stream during destruction. | |
| AutoTimer (std::shared_ptr< spdlog::logger > logger, spdlog::level::level_enum level=spdlog::level::level_enum::info, std::string format=Timer::kDefaultFormat) | |
Create a new AutoTimer that will report to the given spdlog::logger on destruction. | |
| AutoTimer (const AutoTimer &)=default | |
| AutoTimer (AutoTimer &&)=default | |
| AutoTimer & | operator= (const AutoTimer &)=default |
| AutoTimer & | operator= (AutoTimer &&)=default |
| ~AutoTimer () | |
| Destructor of AutoTimer, calls Report(). | |
| std::ostream & | ostream () const |
| Retrieve the output stream object that was passed in the constructor. | |
| const std::shared_ptr< spdlog::logger > & | logger () const |
| Retrieve the logger that was passed in the constructor. | |
| const std::string & | FormatString () const |
| Retrieve the format string that was passed in the constructor. | |
| void | Report () |
Report time (wall, user, system) since construction of AutoTimer() to either a std::ostream or spdlog::logger that was passed in the constructor. | |
| Timer::cpu_times | Elapsed () const noexcept |
| Retrieve the elapsed time since the construction. | |
| 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 string. | |
Private Attributes | |
| Timer | timer_ |
| std::string | format_ |
| std::variant< std::ostream *, std::pair< std::shared_ptr< spdlog::logger >, spdlog::level::level_enum > > | output_ |
Measures execution time between construction and destruction. AutoTimer can output either to a std::ostream or to a spdlog::logger
This class is very useful when you want to measure the execution time of a particular piece of code:
|
explicit |
Create a new AutoTimer that will report time measurements to std::cout when destructed.
| format | Optional format string that specifies how the measured execution time is printed. See Timer::Format(). |
Definition at line 142 of file timer.cc.
References format_, and output_.
Referenced by AutoTimer(), AutoTimer(), operator=(), and operator=().
|
explicit |
Create a new AutoTimer that will report to the given stream during destruction.
| stream | The stream to which output should be written. |
| format | Optional format string that specifies how the measured execution time is printed. See Timer::Format(). |
|
explicit |
Create a new AutoTimer that will report to the given spdlog::logger on destruction.
| logger | The spdlog logger object to which the timer should write. See Loggers and Debug output . |
| level | The logging level at which the message will be logged. |
| format | Optional format string that specifies how the measured execution time is printed. See Timer::Format(). |
|
default |
References AutoTimer().
|
default |
References AutoTimer().
| lf::base::AutoTimer::~AutoTimer | ( | ) |
|
nodiscardnoexcept |
Retrieve the elapsed time since the construction.
Definition at line 186 of file timer.cc.
References timer_.
|
nodiscard |
Return the number of elapsed seconds of the wall clock time, user time and system time as a formatted string.
| format | The fmt format string that is used to format the output. See below for possible fmt arguments. |
The following named arguments can appear in the format parameter:
| name | replacement value |
|---|---|
w | Elapsed().wall |
u | Elapsed().user |
s | Elapsed().system |
t | Elapsed().user + Elapsed().system |
p | (Elapsed().user + Elapsed().system)/Elapsed().wall*100. |
Definition at line 190 of file timer.cc.
References timer_.
Referenced by operator=().
|
nodiscard |
Retrieve the format string that was passed in the constructor.
Definition at line 175 of file timer.cc.
References format_.
Referenced by operator=().
|
nodiscard |
Retrieve the logger that was passed in the constructor.
| std::bad_variant_access | if a std::ostream was passed in the constructor. |
Definition at line 169 of file timer.cc.
References output_.
Referenced by AutoTimer(), and operator=().
References AutoTimer(), Format(), FormatString(), logger(), ostream(), and Report().
References AutoTimer().
|
nodiscard |
Retrieve the output stream object that was passed in the constructor.
| std::bad_variant_access | if a spdlog::logger was passed in the constructor. |
Definition at line 165 of file timer.cc.
References output_.
Referenced by operator=(), and Report().
| void lf::base::AutoTimer::Report | ( | ) |
Report time (wall, user, system) since construction of AutoTimer() to either a std::ostream or spdlog::logger that was passed in the constructor.
std::ostream, this method will insert an additional newline character at the end. Definition at line 177 of file timer.cc.
References format_, ostream(), output_, and timer_.
Referenced by operator=(), and ~AutoTimer().
|
private |
Definition at line 268 of file timer.h.
Referenced by AutoTimer(), AutoTimer(), AutoTimer(), FormatString(), and Report().
|
private |
Definition at line 273 of file timer.h.
Referenced by AutoTimer(), AutoTimer(), AutoTimer(), logger(), ostream(), and Report().
|
private |