OB.DAAC Logo
NASA Logo
Ocean Color Science Software

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()

auto d ( ) const
inlinenoexcept

Return elapsed time in days.

Definition at line 110 of file Stopwatch.hpp.

◆ h()

auto h ( ) const
inlinenoexcept

Return elapsed time in hours.

Definition at line 106 of file Stopwatch.hpp.

◆ m()

auto m ( ) const
inlinenoexcept

Return elapsed time in minutes.

Definition at line 102 of file Stopwatch.hpp.

◆ mark()

time_point 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()

auto ms ( ) const
inlinenoexcept

Return elapsed time in milliseconds.

Definition at line 86 of file Stopwatch.hpp.

◆ now()

auto now ( ) const
inlinenoexcept

Return elapsed time in the duration specified via the template. Use count() to get the actual value of the returned duration).

Template Parameters
TDuration type to cast the elapsed time to.

Definition at line 74 of file Stopwatch.hpp.

◆ ns()

auto ns ( ) const
inlinenoexcept

Return elapsed time in nanoseconds.

Definition at line 78 of file Stopwatch.hpp.

◆ pretty()

std::string pretty ( int  decimals = 6) const
inlinenoexcept

Pretty-print the elapsed time.

Parameters
[in]decimalsOptional, how many decimal places to print seconds to (default = 6).

Definition at line 125 of file Stopwatch.hpp.

◆ pretty_print() [1/2]

static std::string pretty_print ( long  nanoseconds,
int  decimals = 6 
)
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]nanosecondsNanoseconds to print.
[in]decimalsOptional, how many decimal places to print seconds to (default = 6).

Definition at line 163 of file Stopwatch.hpp.

◆ pretty_print() [2/2]

static std::string pretty_print ( std::chrono::duration< T >  duration,
int  decimals = 6 
)
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]durationThe duration to print.
[in]decimalsOptional, how many decimal places to print seconds to (default = 6).

Definition at line 151 of file Stopwatch.hpp.

◆ reset() [1/3]

void reset ( )
inlinenoexcept

Reset stopwatch to current (arbitrary) time.

Definition at line 35 of file Stopwatch.hpp.

◆ reset() [2/3]

void reset ( const d)
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]dNew interval start time. Must be a valid argument for chrono::seconds constructor, e.g., another chrono::duration or a number.

Definition at line 64 of file Stopwatch.hpp.

◆ reset() [3/3]

void reset ( const time_point  t)
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]tNew interval start time.

Definition at line 48 of file Stopwatch.hpp.

◆ s()

auto s ( ) const
inlinenoexcept

Return elapsed time in seconds (alias for seconds()).

Definition at line 98 of file Stopwatch.hpp.

◆ sec()

auto sec ( ) const
inlinenoexcept

Return elapsed time in seconds (alias for seconds()).

Definition at line 94 of file Stopwatch.hpp.

◆ seconds()

auto seconds ( ) const
inlinenoexcept

Return elapsed time in seconds.

Definition at line 90 of file Stopwatch.hpp.

◆ us()

auto us ( ) const
inlinenoexcept

Return elapsed time in microseconds.

Definition at line 82 of file Stopwatch.hpp.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Stopwatch in 
)
friend

Pretty print time elapsed to stream.

Parameters
outTarget output stream
inStopwatch 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: