28 stable releases (3 major)

3.4.0 Dec 18, 2024
3.3.1 Dec 18, 2023
3.3.0 Jun 4, 2023
3.2.0 Mar 20, 2023
0.2.0 Aug 8, 2022

#61 in Date and time

Download history 4058/week @ 2024-09-22 2954/week @ 2024-09-29 2676/week @ 2024-10-06 3060/week @ 2024-10-13 1336/week @ 2024-10-20 2841/week @ 2024-10-27 2278/week @ 2024-11-03 2562/week @ 2024-11-10 2380/week @ 2024-11-17 1624/week @ 2024-11-24 1607/week @ 2024-12-01 1801/week @ 2024-12-08 2504/week @ 2024-12-15 64/week @ 2024-12-22 130/week @ 2024-12-29 1547/week @ 2025-01-05

4,524 downloads per month
Used in 2 crates

MIT/Apache

61KB
785 lines

libsw

Crates.io Crates.io docs.rs

libsw is a comprehensive and safe stopwatch implementation.

The minimum supported version of Rust is 1.61.0.

License

Dual licensed under the MIT or Apache 2.0 licenses.


lib.rs:

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

Name Features enabled Description
default std_instant, std_systemtime Enabled by default.
std Depends on the standard library. Implements std::error::Error for Error.
nightly Implements core::error::Error for Error if std is not enabled. Requires a nightly compiler.
std_instant std Implements Instant for std::time::Instant. Exposes Sw type alias.
std_systemtime std Implements Instant for std::time::SystemTime. Exposes SystemSw type alias.
tokio std Implements Instant for tokio::time::Instant. Exposes TokioSw type alias.
coarsetime std Implements Instant for coarsetime::Instant. Exposes CoarseSw type alias.
quanta std Implements Instant for quanta::Instant. Exposes QuantaSw type alias.
time std Deprecated. 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)]).

Dependencies

~0–7.5MB
~55K SLoC