| Crates.io | systime |
| lib.rs | systime |
| version | 0.0.3 |
| created_at | 2025-10-15 03:49:40.205478+00 |
| updated_at | 2025-10-31 15:34:17.241138+00 |
| description | Portable timers that handle system sleep consistently. |
| homepage | |
| repository | https://github.com/sameer/systime |
| max_upload_size | |
| id | 1883638 |
| size | 80,710 |
A Rust crate for portable timers that handle system sleep consistently.
Time in the standard library, tokio, and generally every Rust crate has platform-dependent behavior:
CLOCK_MONOTONIC excludes time spent sleeping (rust-lang/rust#71860)CLOCK_UPTIME_RAW (or mach_absolute_time) excludes time spent sleepingQueryPerformanceCounter includes time spent sleeping (rust-lang/rust#79462)This makes it difficult to write portable code with predictable timer behavior, especially in applications that need to account for the real-world time that has passed (including system sleep).
systime offers a simple API where you explicitly choose whether to track or ignore system sleep.
Sleep is a blanket term for any time a process spends suspended. Real-world time passes, but a process that isn't executing and won't see it. A clock that tracks sleep is still monotonic, it just has sudden jumps.
A few examples:
timerfd with CLOCK_MONOTONIC (ignore sleep) or CLOCK_BOOTTIME (track sleep)kqueue + EVFILT_TIMER with mach absolute time (ignore sleep) or mach continuous time (track sleep)systime supports both the tokio and smol async ecosystems via feature flags.
Tokio support is enabled by default.
Tracking sleep is useful for:
Ignoring sleep is useful for:
While every effort has been made to ensure timers are fast and efficient (i.e. sub-millisecond precision on Windows), this crate does use system timer facilities and there are limits on these resources. Hence why most operations can return an error.
Use these timers sparingly and include a fallback to the appropriate equivalent (i.e. tokio::time for tokio) in case of failure. Alternatively, a timer wheel-esque approach could be used.