High Precision Clock
high_precision_clock is a Rust library designed for high-precision timekeeping, especially useful for applications that require accurate time drift correction in cloud environments. The crate leverages system features like the Time Stamp Counter (TSC) for x86_64 Linux systems to provide highly precise timestamps with minimal drift. It is suitable for both synchronous and asynchronous contexts, making it versatile for various applications, including trading systems and time-sensitive analytics.
Key Features
- High Precision Timekeeping: Provides timestamps with minimal drift and high accuracy.
- TSC-based Timing: Uses the CPU’s Time Stamp Counter (TSC) for precise timing on supported systems.
- Drift Correction: Periodically recalibrates to correct drift against the system clock.
- Async Compatibility: Works seamlessly in both async and sync contexts.
- Cloud-Friendly: Optimized for cloud environments with potentially non-invariant TSC.
Example Usage
Here’s how you can initialize and use high_precision_clock in both synchronous and asynchronous contexts.
Synchronous Example
use HighPrecisionClock;
use Duration;
Asynchronous Example
To run the crate in an asynchronous context, enable the async feature in your Cargo.toml:
[]
= { = "0.1", = ["async"] }
= { = "1", = ["full"] }
Then, use it as shown below:
use HighPrecisionClock;
use Duration;
async
Installation
To use high_precision_clock, add it to your Cargo.toml:
[]
= "0.1"
If you want to use it in an async context, enable the async feature as shown:
[]
= { = "0.1", = ["async"] }
= { = "1", = ["full"] }
License
This project is licensed under the MIT License.