LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
|
Timer class to measure time. More...
#include <lf/base/timer.h>
Classes | |
struct | cpu_times |
Packages the elapsed wall clock time, user process CPU time, and system process CPU time. More... | |
Public Member Functions | |
Timer (bool start=true) noexcept | |
Construct a new timer and optionally start it immediately. | |
bool | IsStopped () const noexcept |
Is the timer currently stopped? | |
cpu_times | Elapsed () const noexcept |
Elapsed time since timer start, doesn't stop the timer. | |
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 string. | |
void | Start () noexcept |
(Re)starts the timer, i.e. the timer starts counting from 0 when this method is called. | |
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. | |
Static Public Attributes | |
static std::string | kDefaultFormat |
Default format string that is used by Format() | |
Private Attributes | |
cpu_times | times_ |
bool | is_stopped_ |
Timer class to measure time.
|
inlineexplicitnoexcept |
Construct a new timer and optionally start it immediately.
start | If set to true, the timer will start immediately. Otherwise it will stay in status stopped. |
Definition at line 101 of file timer.h.
References is_stopped_, Start(), and times_.
|
noexcept |
Elapsed time since timer start, doesn't stop the timer.
Definition at line 86 of file timer.cc.
References IsStopped(), lf::base::Timer::cpu_times::system, times_, lf::base::Timer::cpu_times::user, and lf::base::Timer::cpu_times::wall.
Referenced by lf::base::AutoTimer::Elapsed().
std::string lf::base::Timer::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 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 100 of file timer.cc.
References lf::base::Timer::cpu_times::system, times_, lf::base::Timer::cpu_times::user, and lf::base::Timer::cpu_times::wall.
Referenced by lf::base::AutoTimer::Format(), and lf::base::AutoTimer::Report().
|
inlinenoexcept |
Is the timer currently stopped?
Definition at line 115 of file timer.h.
References is_stopped_.
Referenced by Elapsed(), Resume(), Stop(), and lf::base::AutoTimer::~AutoTimer().
|
noexcept |
Resume the timer, i.e. start counting from where we stopped the last time.
Definition at line 132 of file timer.cc.
References IsStopped(), Start(), lf::base::Timer::cpu_times::system, times_, lf::base::Timer::cpu_times::user, and lf::base::Timer::cpu_times::wall.
|
noexcept |
|
noexcept |
stop the timer, stop counting the elapsed time.
Definition at line 119 of file timer.cc.
References is_stopped_, IsStopped(), lf::base::Timer::cpu_times::system, times_, lf::base::Timer::cpu_times::user, and lf::base::Timer::cpu_times::wall.
Referenced by lf::base::AutoTimer::~AutoTimer().
|
private |
|
inlinestatic |
|
private |