Crate libsw

Source
Expand description

libsw is a comprehensive stopwatch implementation.

It offers checked stopping and arithmetic, precise control over when operations occur, and supports arbitrary timekeeping types.

If you want to do benchmarking, please use something like Criterion.

§Introduction

libsw provides the StopwatchImpl type as a stopwatch.

This implementation is agnostic to the timekeeping type used, by virtue of being generic. Any type I that implements the Instant trait (as in StopwatchImpl<I>) can be used for timekeeping.

Instant is implemented for several timekeeping types out of the box (see timekeeping support). If present, these implementations are exposed as type aliases.

§Features

NameFeatures enabledDescription
defaultstd_instant, std_systemtimeEnabled by default.
stdDepends on the standard library. Implements std::error::Error for Error.
nightlyImplements core::error::Error for Error if std is not enabled. Requires a nightly compiler.
std_instantstdImplements Instant for std::time::Instant. Exposes Sw type alias.
std_systemtimestdImplements Instant for std::time::SystemTime. Exposes SystemSw type alias.
tokiostdImplements Instant for tokio::time::Instant. Exposes TokioSw type alias.
coarsetimestdImplements Instant for coarsetime::Instant. Exposes CoarseSw type alias.
quantastdImplements Instant for quanta::Instant. Exposes QuantaSw type alias.
timestdDeprecated. Implements Instant for time::Instant. Exposes TimeSw type alias.

§Timekeeping support

libsw can be used with any timekeeping type that implements Instant, as long as the appropriate feature flag is enabled.

See Instant’s documentation for a list of types supported out of the box.

§no_std support

The std feature flag unsets #[no_std]. It is enabled by default, but you can disable it by disabling the default features.

In Cargo.toml,

[dependencies]
# replace '...' with the appropriate version
libsw = { version = ..., default-features = false }

§Compiler support

Standalone, the minimum supported version of Rust is 1.61.0. Adding dependencies may bump this.

§Safety

libsw contains no unsafe code (#![forbid(unsafe_code)]).

Structs§

Guard
A running, guarded, stopwatch. When dropped, the stopwatch will automatically stop.
StopwatchImpl
A stopwatch measures and accumulates elapsed time between starts and stops.

Enums§

Error
Enumeration over possible errors.

Traits§

Instant
A trait outlining the behavior of a timekeeping type.

Type Aliases§

CoarseSwcoarsetime
Alias to StopwatchImpl using the coarsetime crate’s Instant type.
QuantaSwquanta
Alias to StopwatchImpl using the quanta crate’s Instant type.
Result
Alias to Result<T, Error>.
StopwatchDeprecatedstd_instant
Deprecated alias to the “default” stopwatch.
Swstd_instant
Alias to StopwatchImpl using the standard library’s Instant type.
SystemSwstd_systemtime
Alias to StopwatchImpl using the standard library’s SystemTime type.
TimeSwDeprecatedtime
Alias to StopwatchImpl using the time crate’s Instant type.
TokioSwtokio
Alias to StopwatchImpl using Tokio’s Instant type.