1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Provides efficient mechanisms to capture the current timestamp and measure elapsed time.
//!
//! This crate offers a [`Clock`] that can provide timestamps with low overhead, making it
//! suitable for high-frequency querying scenarios like metrics collection and logging.
//! The clock prioritizes efficiency over absolute precision, making it ideal for applications
//! that need to capture thousands of timestamps per second.
//!
//! # Key features
//!
//! - **Low overhead**: Optimized for rapid, repeated timestamp capture on supported platforms
//! - **Monotonic timestamps**: Guarantees that timestamps always increase
//! - **Cross-platform**: Works on all platforms, with optimizations for Windows and Linux
//! - **Standard library compatibility**: Converts to/from [`std::time::Instant`]
//!
//! # Trade-offs
//!
//! On optimized platforms (Windows, Linux):
//!
//! - May lag behind wall-clock time by a few milliseconds
//! - May not reflect explicit wall clock adjustments (e.g., NTP synchronization)
//! - Optimized for frequency over precision
//!
//! On other platforms, performance is equivalent to `std::time::Instant`.
//!
//! # Hot loop performance comparison (optimized platforms)
//!
//! | Platform | `fast_time` | `std::time` |
//! |--------------------------|-------------|-------------|
//! | Windows | 2 ns | 25 ns |
//! | Linux | 6 ns | 19 ns |
//!
//! # Basic usage
//!
//! ```rust
//! use fast_time::Clock;
//!
//! let mut clock = Clock::new();
//! let start = clock.now();
//!
//! // Do some work...
//! std::thread::sleep(std::time::Duration::from_millis(10));
//!
//! let elapsed = start.elapsed(&mut clock);
//! println!("Operation took: {:?}", elapsed);
//! ```
//!
//! # High-frequency timestamp collection
//!
//! ```rust
//! use std::time::Duration;
//!
//! use fast_time::Clock;
//!
//! let mut clock = Clock::new();
//! let mut timestamps = Vec::new();
//!
//! // Collect many timestamps rapidly
//! for _ in 0..1000 {
//! timestamps.push(clock.now());
//! }
//!
//! // Measure elapsed time between first and last
//! let total_time = timestamps
//! .last()
//! .unwrap()
//! .saturating_duration_since(*timestamps.first().unwrap());
//!
//! println!(
//! "Collected {} timestamps in {:?}",
//! timestamps.len(),
//! total_time
//! );
//! ```
//!
//! # Supported platforms
//!
//! This crate provides optimized implementations for:
//!
//! * Windows
//! * Linux
//!
//! On other platforms, the crate functions as a lightweight wrapper around the
//! Rust standard library's `Instant` type, ensuring the crate compiles on all
//! platforms without requiring platform-specific optimizations.
pub use *;
pub use *;