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>
|
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:
std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2), "mesh.msh");
auto fes =
std::make_shared<lf::uscalfe::FeSpaceLagrangeO1<double>>(reader.mesh());
fes->LocGlobMap().NumDofs());
{
std::cout << "Start assembly" << std::endl;
emp, sm);
}
- See also
- Timer
Definition at line 182 of file timer.h.
◆ AutoTimer() [1/5]
Create a new AutoTimer that will report time measurements to std::cout
when destructed.
- Parameters
-
format | Optional format string that specifies how the measured execution time is printed. See Timer::Format(). |
Definition at line 142 of file timer.cc.
◆ AutoTimer() [2/5]
Create a new AutoTimer that will report to the given stream during destruction.
- Parameters
-
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(). |
Definition at line 145 of file timer.cc.
◆ AutoTimer() [3/5]
lf::base::AutoTimer::AutoTimer |
( |
std::shared_ptr< spdlog::logger > | logger, |
|
|
spdlog::level::level_enum | level = spdlog::level::level_enum::info, |
|
|
std::string | format = Timer::kDefaultFormat ) |
|
explicit |
Create a new AutoTimer that will report to the given spdlog::logger
on destruction.
- Parameters
-
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(). |
Definition at line 148 of file timer.cc.
◆ AutoTimer() [4/5]
lf::base::AutoTimer::AutoTimer |
( |
const AutoTimer & | | ) |
|
|
default |
◆ AutoTimer() [5/5]
lf::base::AutoTimer::AutoTimer |
( |
AutoTimer && | | ) |
|
|
default |
◆ ~AutoTimer()
lf::base::AutoTimer::~AutoTimer |
( |
| ) |
|
◆ Elapsed()
◆ Format()
Return the number of elapsed seconds of the wall clock time, user time and system time as a formatted string.
- Parameters
-
format | The fmt format string that is used to format the output. See below for possible fmt arguments. |
- Returns
- The formatted string
format named arguments:
The following named arguments can appear in the format
parameter:
Definition at line 190 of file timer.cc.
References lf::base::Timer::Format(), and timer_.
◆ FormatString()
const std::string & lf::base::AutoTimer::FormatString |
( |
| ) |
const |
Retrieve the format string that was passed in the constructor.
Definition at line 175 of file timer.cc.
References format_.
◆ logger()
const std::shared_ptr< spdlog::logger > & lf::base::AutoTimer::logger |
( |
| ) |
const |
Retrieve the logger that was passed in the constructor.
- Exceptions
-
std::bad_variant_access | if a std::ostream was passed in the constructor. |
Definition at line 169 of file timer.cc.
References output_.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ ostream()
std::ostream & lf::base::AutoTimer::ostream |
( |
| ) |
const |
Retrieve the output stream object that was passed in the constructor.
- Exceptions
-
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 Report().
◆ Report()
void lf::base::AutoTimer::Report |
( |
| ) |
|
◆ format_
std::string lf::base::AutoTimer::format_ |
|
private |
◆ output_
std::variant<std::ostream*, std::pair<std::shared_ptr<spdlog::logger>, spdlog::level::level_enum> > lf::base::AutoTimer::output_ |
|
private |
◆ timer_
Timer lf::base::AutoTimer::timer_ |
|
private |
The documentation for this class was generated from the following files:
- /__w/lehrfempp/lehrfempp/lib/lf/base/timer.h
- /__w/lehrfempp/lehrfempp/lib/lf/base/timer.cc