#monotonic #duration #time

boot-time

Monotonic time that takes into account time a system was suspended (if the system supports this)

2 releases

0.1.2 Sep 26, 2023
0.1.1 Sep 25, 2023
0.1.0 Sep 25, 2023

#522 in Operating systems

Download history 21/week @ 2024-11-15 6/week @ 2024-11-22 35/week @ 2024-11-29 28/week @ 2024-12-06 25/week @ 2024-12-13 7/week @ 2024-12-20 3/week @ 2025-01-10 15/week @ 2025-01-17 4/week @ 2025-01-24 18/week @ 2025-01-31 40/week @ 2025-02-07 37/week @ 2025-02-14 40/week @ 2025-02-21 34/week @ 2025-02-28

157 downloads per month
Used in completeio

MIT license

33KB
556 lines

Boot time

Crates.io Docs.rs License

This library reimplements std::time::Instant to use suspend-aware monotonic time if target system supports it. Otherwise is uses monotonic time or reexports std::time::Instant.


lib.rs:

Temporal quantification that takes into account the time a system spent suspended.

Note: Some systems like FreeBSD, DragonFlyBSD, NetBSD, AIX, Fuchsia, Emscripten don't support CLOCK_BOOTIME.

For compatibility CLOCK_MONOTONIC is used as a fallback.

Windows QueryPerformanceCounter includes suspended time. So for Windows and unsupported platforms std::time::Instant is just reexported.

Examples

Using Instant to calculate how long a function took to run:

use boot_time::Instant;

let now = Instant::now();

// Calling a slow function, it may take a while
slow_function();

let elapsed_time = now.elapsed();
println!("Running slow_function() took {} seconds.", elapsed_time.as_secs());

Dependencies

~46KB