27 stable releases (3 major)

3.3.1 Dec 18, 2023
3.3.0 Jun 4, 2023
3.2.4 Apr 14, 2023
3.2.0 Mar 20, 2023
0.2.0 Aug 8, 2022

#55 in Date and time

Download history 2378/week @ 2024-03-04 2354/week @ 2024-03-11 1594/week @ 2024-03-18 2386/week @ 2024-03-25 2732/week @ 2024-04-01 2548/week @ 2024-04-08 2038/week @ 2024-04-15 2155/week @ 2024-04-22 1840/week @ 2024-04-29 1844/week @ 2024-05-06 2764/week @ 2024-05-13 1870/week @ 2024-05-20 1781/week @ 2024-05-27 1252/week @ 2024-06-03 1347/week @ 2024-06-10 1678/week @ 2024-06-17

6,075 downloads per month
Used in ncount




Crates.io Crates.io docs.rs

libsw is a comprehensive and safe stopwatch implementation.

The minimum supported version of Rust is 1.61.0.


Dual licensed under the MIT or Apache 2.0 licenses.


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.


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.


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.
time std Implements Instant for time::Instant. Exposes TimeSw type alias. Bumps MSRV to 1.62.1.
coarsetime std Implements Instant for coarsetime::Instant. Exposes CoarseSw type alias.
quanta std Implements Instant for quanta::Instant. Exposes QuantaSw 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,

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

Compiler support

The minimum supported version of Rust is 1.61.0.


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


~53K SLoC