boot_time/lib.rs
1//! Temporal quantification that takes into account the time a system spent suspended.
2//!
3//! Note: Some systems like FreeBSD, DragonFlyBSD, NetBSD, AIX, Fuchsia,
4//! Emscripten don't support CLOCK_BOOTIME.
5//!
6//! For compatibility CLOCK_MONOTONIC is used as a fallback.
7//!
8//! Windows QueryPerformanceCounter includes suspended time. So for Windows and
9//! unsupported platforms `std::time::Instant` is just reexported.
10//!
11//! # Examples
12//!
13//! Using [`Instant`] to calculate how long a function took to run:
14//!
15//! ```ignore (incomplete)
16//! use boot_time::Instant;
17//!
18//! let now = Instant::now();
19//!
20//! // Calling a slow function, it may take a while
21//! slow_function();
22//!
23//! let elapsed_time = now.elapsed();
24//! println!("Running slow_function() took {} seconds.", elapsed_time.as_secs());
25//! ```
26
27pub use core::time::Duration;
28
29cfg_if::cfg_if! {
30 if #[cfg(unix)] {
31 mod time;
32 mod sys;
33 mod sys_common;
34
35 pub use self::time::Instant;
36 } else {
37 pub use std::time::Instant;
38 }
39}
40
41#[cfg(test)]
42mod tests;