werkzeugkiste::timing namespace

Stop watch & additional helpers on top of std::chrono.

Contents

These utilities are intended to hide some of the template boilerplate of std::chrono.

Classes

template<typename Clock = std::chrono::steady_clock>
class StopWatch_
A stop watch with configurable clock.

Typedefs

using StopWatch = StopWatch_<std::chrono::steady_clock>
Typedef for the default stop watch.

Functions

template<typename Duration>
auto DurationAbbreviation() -> std::string
Returns the abbreviation for the given duration type, e.g. "hrs" for std::chrono::hours.
template<typename Clock>
auto ClockTypeName() -> std::string
Returns the fully qualified name of the given clock type, e.g. "std::chrono::system_clock".
template<typename Duration>
auto PrecisionTypeName() -> std::string
Returns the fully qualified name of the given duration type, e.g. "std::chrono::nanoseconds".
template<typename DurationFrom, typename DurationTo>
auto CastToTicks(const DurationFrom& duration) -> double constexpr
Returns the number of ticks for the given std::chrono::duration at a potentially different precision.
template<typename Duration>
auto ToSeconds(const Duration& duration) -> double constexpr
Returns the number of seconds for the given std::chrono::duration.
template<typename Duration>
auto ToMilliseconds(const Duration& duration) -> double constexpr
Returns the number of milliseconds for the given std::chrono::duration.
template<typename Duration>
auto ToMicroseconds(const Duration& duration) -> double constexpr
Returns the number of microseconds for the given std::chrono::duration.
template<typename Duration>
auto ToNanoseconds(const Duration& duration) -> double constexpr
Returns the number of nanoseconds for the given std::chrono::duration.
auto SecondsToString(unsigned int seconds) -> WERKZEUGKISTE_TIMING_EXPORT std::string
Returns a human readable string approximating the given time.
auto SetTocFormat(bool print_labels_aligned = false, int fixed_number_width = 0, int number_precision = 0) -> WERKZEUGKISTE_TIMING_EXPORT void
Set output format for the toc_xxx() functions.
auto MuteToc() -> WERKZEUGKISTE_TIMING_EXPORT void
Mute future toc_xxx calls, i.e. no output will be displayed.
auto UnmuteToc() -> WERKZEUGKISTE_TIMING_EXPORT void
Unmute, i.e. future toc_xxx calls will display the elapsed time again.
auto Tic(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT void
Starts (or restarts) a.
auto TocSeconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT void
Displays the elapsed time in seconds.
auto TocMilliseconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT void
Displays the elapsed time in milliseconds.
auto TocMicroseconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT void
Displays the elapsed time in microseconds.
auto TocNanoseconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT void
Displays the elapsed time in nanoseconds.
auto TTocSeconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT double
Returns the elapsed time in seconds.
auto TTocMilliseconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT double
Returns the elapsed time in milliseconds.
auto TTocMicroseconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT double
Returns the elapsed time in microseconds.
auto TTocNanoseconds(const std::string& label = std::string()) -> WERKZEUGKISTE_TIMING_EXPORT double
Returns the elapsed time in nanoseconds.

Typedef documentation

using werkzeugkiste::timing::StopWatch = StopWatch_<std::chrono::steady_clock>

Typedef for the default stop watch.

Function documentation

template<typename Duration>
std::string werkzeugkiste::timing::DurationAbbreviation()

Returns the abbreviation for the given duration type, e.g. "hrs" for std::chrono::hours.

template<typename Clock>
std::string werkzeugkiste::timing::ClockTypeName()

Returns the fully qualified name of the given clock type, e.g. "std::chrono::system_clock".

template<typename Duration>
std::string werkzeugkiste::timing::PrecisionTypeName()

Returns the fully qualified name of the given duration type, e.g. "std::chrono::nanoseconds".

template<typename DurationFrom, typename DurationTo>
double werkzeugkiste::timing::CastToTicks(const DurationFrom& duration) constexpr

Returns the number of ticks for the given std::chrono::duration at a potentially different precision.

template<typename Duration>
double werkzeugkiste::timing::ToSeconds(const Duration& duration) constexpr

Returns the number of seconds for the given std::chrono::duration.

template<typename Duration>
double werkzeugkiste::timing::ToMilliseconds(const Duration& duration) constexpr

Returns the number of milliseconds for the given std::chrono::duration.

template<typename Duration>
double werkzeugkiste::timing::ToMicroseconds(const Duration& duration) constexpr

Returns the number of microseconds for the given std::chrono::duration.

template<typename Duration>
double werkzeugkiste::timing::ToNanoseconds(const Duration& duration) constexpr

Returns the number of nanoseconds for the given std::chrono::duration.

WERKZEUGKISTE_TIMING_EXPORT std::string werkzeugkiste::timing::SecondsToString(unsigned int seconds)

Returns a human readable string approximating the given time.

For example, ‘SecondsToString(3700 * 24 + 50) = '1 day 40 minutes’`.

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::SetTocFormat(bool print_labels_aligned = false, int fixed_number_width = 0, int number_precision = 0)

Set output format for the toc_xxx() functions.

Parameters
print_labels_aligned If true, all timer labels will be displayed at a fixed width (which is determined by the longest label).
fixed_number_width If > 0, numbers are displayed using this fixed width.
number_precision If > 0, defines the decimal precision for displaying time measurements.

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::MuteToc()

Mute future toc_xxx calls, i.e. no output will be displayed.

Users of the C++ library should usually prefer the TIC/TOC macros and #define NO_TICTOC instead. The mute/unmute calls are intended for a (future) Python interface where it's less convenient to rebuild the library. With mute() you still "suffer" from unnecessary function call overheads, whereas with NO_TICTOC all function calls would be eliminated.

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::UnmuteToc()

Unmute, i.e. future toc_xxx calls will display the elapsed time again.

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::Tic(const std::string& label = std::string())

Starts (or restarts) a.

Parameters
label You can specify a label to differentiate multiple StopWatches.

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::TocSeconds(const std::string& label = std::string())

Displays the elapsed time in seconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::TocMilliseconds(const std::string& label = std::string())

Displays the elapsed time in milliseconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::TocMicroseconds(const std::string& label = std::string())

Displays the elapsed time in microseconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT void werkzeugkiste::timing::TocNanoseconds(const std::string& label = std::string())

Displays the elapsed time in nanoseconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT double werkzeugkiste::timing::TTocSeconds(const std::string& label = std::string())

Returns the elapsed time in seconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT double werkzeugkiste::timing::TTocMilliseconds(const std::string& label = std::string())

Returns the elapsed time in milliseconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT double werkzeugkiste::timing::TTocMicroseconds(const std::string& label = std::string())

Returns the elapsed time in microseconds.

Parameters
label Label of the corresponding

WERKZEUGKISTE_TIMING_EXPORT double werkzeugkiste::timing::TTocNanoseconds(const std::string& label = std::string())

Returns the elapsed time in nanoseconds.

Parameters
label Label of the corresponding