https://github.com/fast/fastant
A drop-in replacement for std::time::Instant that is faster and more accurate.
https://github.com/fast/fastant
instant rust rust-lang time
Last synced: about 1 year ago
JSON representation
A drop-in replacement for std::time::Instant that is faster and more accurate.
- Host: GitHub
- URL: https://github.com/fast/fastant
- Owner: fast
- License: apache-2.0
- Created: 2024-08-12T13:46:49.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-13T09:09:49.000Z (over 1 year ago)
- Last Synced: 2025-04-06T03:12:52.429Z (about 1 year ago)
- Topics: instant, rust, rust-lang, time
- Language: Rust
- Homepage: https://crates.io/crates/fastant
- Size: 252 KB
- Stars: 23
- Watchers: 0
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fastant
A drop-in replacement for [`std::time::Instant`](https://doc.rust-lang.org/std/time/struct.Instant.html) that measures time with high performance and high accuracy powered by [Time Stamp Counter (TSC)](https://en.wikipedia.org/wiki/Time_Stamp_Counter).
[](https://github.com/fast/fastant/actions)
[](https://docs.rs/fastant/)
[](https://crates.io/crates/fastant)
[](LICENSE)
## Usage
```toml
[dependencies]
fastant = "0.1"
```
```rust
fn main() {
let start = fastant::Instant::now();
let duration: std::time::Duration = start.elapsed();
}
```
## Motivation
This library is used by a high performance tracing library [`fastrace`](https://github.com/fast/fastrace). The main purpose is to use [Time Stamp Counter (TSC)](https://en.wikipedia.org/wiki/Time_Stamp_Counter) on x86 processors to measure time at high speed without losing much accuracy.
## Platform Support
Currently, only the Linux on `x86` or `x86_64` is backed by Time Stamp Counter (TSC). On other platforms, Fastant falls back to `std::time`. If TSC is unstable, it will also fall back to `std::time`.
If speed is privileged over accuracy when fallback occurs, you can use `fallback-coarse` feature to use coarse time:
```toml
[dependencies]
fastant = { version = "0.1", features = ["fallback-coarse"] }
```