ocssw
V2022
|
#include <Stopwatch.hpp>
Public Member Functions | |
void | reset () noexcept |
void | reset (const time_point t) noexcept |
template<typename T > | |
void | reset (const T d) noexcept |
template<class T = clock::duration> | |
auto | now () const noexcept |
auto | ns () const noexcept |
auto | us () const noexcept |
auto | ms () const noexcept |
auto | seconds () const noexcept |
auto | sec () const noexcept |
auto | s () const noexcept |
auto | m () const noexcept |
auto | h () const noexcept |
auto | d () const noexcept |
time_point | mark () |
std::string | pretty (int decimals=6) const noexcept |
Static Public Member Functions | |
template<typename T > | |
static std::string | pretty_print (std::chrono::duration< T > duration, int decimals=6) noexcept |
static std::string | pretty_print (long nanoseconds, int decimals=6) noexcept |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Stopwatch &in) |
Detailed Description
Simple timer for profiling sections of code.
This class uses std::chrono::steady_clock
, so marks are inherently arbitrary. To get the elapsed time, it simply uses steady_clock::now() - mark
.
All time_point
types are steady_clock::time_point
.
Example
Reconstructing Stopwatches
Definition at line 29 of file Stopwatch.hpp.
Member Function Documentation
◆ d()
|
inlinenoexcept |
Return elapsed time in days.
Definition at line 110 of file Stopwatch.hpp.
◆ h()
|
inlinenoexcept |
Return elapsed time in hours.
Definition at line 106 of file Stopwatch.hpp.
◆ m()
|
inlinenoexcept |
Return elapsed time in minutes.
Definition at line 102 of file Stopwatch.hpp.
◆ mark()
|
inline |
Return the mark in its native format.
This functionality should not be relied upon, as the API is no longer within the scope of this class.
Definition at line 117 of file Stopwatch.hpp.
◆ ms()
|
inlinenoexcept |
Return elapsed time in milliseconds.
Definition at line 86 of file Stopwatch.hpp.
◆ now()
|
inlinenoexcept |
Return elapsed time in the duration specified via the template. Use count()
to get the actual value of the returned duration).
- Template Parameters
-
T Duration type to cast the elapsed time to.
Definition at line 74 of file Stopwatch.hpp.
◆ ns()
|
inlinenoexcept |
Return elapsed time in nanoseconds.
Definition at line 78 of file Stopwatch.hpp.
◆ pretty()
|
inlinenoexcept |
Pretty-print the elapsed time.
- Parameters
-
[in] decimals Optional, how many decimal places to print seconds to (default = 6).
Definition at line 125 of file Stopwatch.hpp.
◆ pretty_print() [1/2]
|
inlinestaticnoexcept |
Pretty-print the given nanoseconds as <days>:<hours>:<minutes>:<seconds>.<decimals>.
Days, hours, etc, will be omitted for times too small. This functionality should be placed elsewhere, probably. Some kind of TimeUtils library or into focs::TimePoint itself, maybe.
- Parameters
-
[in] nanoseconds Nanoseconds to print. [in] decimals Optional, how many decimal places to print seconds to (default = 6).
Definition at line 163 of file Stopwatch.hpp.
◆ pretty_print() [2/2]
|
inlinestaticnoexcept |
Pretty-print the given duration as <days>:<hours>:<minutes>:<seconds>.<decimals>.
Days, hours, etc, will be omitted for times too small. This functionality should be placed elsewhere, probably. Some kind of TimeUtils library or into focs::TimePoint itself, maybe.
- Parameters
-
[in] duration The duration to print. [in] decimals Optional, how many decimal places to print seconds to (default = 6).
Definition at line 151 of file Stopwatch.hpp.
◆ reset() [1/3]
|
inlinenoexcept |
Reset stopwatch to current (arbitrary) time.
Definition at line 35 of file Stopwatch.hpp.
◆ reset() [2/3]
|
inlinenoexcept |
Reset stopwatch to specified mark. This function is mostly for testing.
Due to implementation, the time set is actually steady_clock::now() - t
so that, e.g., setting it to a duration
of 10 seconds will actually cause seconds()
to return 10.
- Parameters
-
[in] d New interval start time. Must be a valid argument for chrono::seconds
constructor, e.g., anotherchrono::duration
or a number.
Definition at line 64 of file Stopwatch.hpp.
◆ reset() [3/3]
|
inlinenoexcept |
Reset stopwatch to specified mark. This function is mostly for testing.
Due to implementation, the time set is actually steady_clock::now() - t
so that, e.g., setting it to a time_point
constructed from a duration
of 10 seconds will actually cause seconds()
to return 10.
- Parameters
-
[in] t New interval start time.
Definition at line 48 of file Stopwatch.hpp.
◆ s()
|
inlinenoexcept |
Return elapsed time in seconds (alias for seconds()
).
Definition at line 98 of file Stopwatch.hpp.
◆ sec()
|
inlinenoexcept |
Return elapsed time in seconds (alias for seconds()
).
Definition at line 94 of file Stopwatch.hpp.
◆ seconds()
|
inlinenoexcept |
Return elapsed time in seconds.
Definition at line 90 of file Stopwatch.hpp.
◆ us()
|
inlinenoexcept |
Return elapsed time in microseconds.
Definition at line 82 of file Stopwatch.hpp.
Friends And Related Function Documentation
◆ operator<<
Pretty print time elapsed to stream.
- Parameters
-
out Target output stream in Stopwatch to print
- Returns
- Given output stream, for chaining
Definition at line 137 of file Stopwatch.hpp.
The documentation for this class was generated from the following file:
- /gfs-oceanweb/web/ocssw/ocssw_src/include/focs/Stopwatch.hpp