-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tison <[email protected]>
- Loading branch information
Showing
9 changed files
with
141 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,37 @@ | ||
# minstant | ||
[![Actions Status](https://github.com/tikv/minstant/workflows/CI/badge.svg)](https://github.com/tikv/minstant/actions) | ||
[![Build Status](https://travis-ci.org/tikv/minstant.svg?branch=master)](https://travis-ci.org/tikv/minstant) | ||
[![Documentation](https://docs.rs/minstant/badge.svg)](https://docs.rs/minstant/) | ||
[![Crates.io](https://img.shields.io/crates/v/minstant.svg)](https://crates.io/crates/minstant) | ||
[![LICENSE](https://img.shields.io/github/license/tikv/minstant.svg)](https://github.com/tikv/minstant/blob/master/LICENSE) | ||
# 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 [TSC](https://en.wikipedia.org/wiki/Time_Stamp_Counter). | ||
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). | ||
|
||
[![Actions Status](https://github.com/fast/fastant/workflows/CI/badge.svg)](https://github.com/fast/fastant/actions) | ||
[![Documentation](https://docs.rs/fastant/badge.svg)](https://docs.rs/fastant/) | ||
[![Crates.io](https://img.shields.io/crates/v/fastant.svg)](https://crates.io/crates/fastant) | ||
[![LICENSE](https://img.shields.io/github/license/fast/fastant.svg)](LICENSE) | ||
|
||
## Usage | ||
|
||
```toml | ||
[dependencies] | ||
minstant = "0.1" | ||
fastant = "0.1" | ||
``` | ||
|
||
```rust | ||
let start = minstant::Instant::now(); | ||
|
||
// Code snipppet to measure | ||
|
||
let duration: std::time::Duration = start.elapsed(); | ||
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 [`minitrace-rust`](https://github.com/tikv/minitrace-rust). The main purpose is to use [TSC](https://en.wikipedia.org/wiki/Time_Stamp_Counter) on x86 processors to measure time at high speed without losing much accuracy. | ||
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 [TSC](https://en.wikipedia.org/wiki/Time_Stamp_Counter). On other platforms, `minstant` falls back to `std::time`. If TSC is unstable, it will also fall back to `std::time`. | ||
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] | ||
minstant = { version = "0.1", features = ["fallback-coarse"] } | ||
``` | ||
|
||
## Benchmark | ||
|
||
Benchmark platform is `Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz` on CentOS 7. | ||
|
||
```sh | ||
> cargo criterion | ||
|
||
Instant::now()/minstant time: [10.449 ns 10.514 ns 10.619 ns] | ||
Instant::now()/quanta time: [31.467 ns 31.628 ns 31.822 ns] | ||
Instant::now()/std time: [26.831 ns 26.924 ns 27.016 ns] | ||
minstant::Anchor::new() time: [46.987 ns 47.243 ns 47.498 ns] | ||
minstant::Instant::as_unix_nanos() time: [15.287 ns 15.318 ns 15.350 ns] | ||
fastant = { version = "0.1", features = ["fallback-coarse"] } | ||
``` | ||
|
||
![Benchmark](benchmark.jpeg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
comment_width = 120 | ||
edition = "2021" | ||
format_code_in_doc_comments = true | ||
group_imports = "StdExternalCrate" | ||
imports_granularity = "Item" | ||
normalize_comments = true | ||
overflow_delimited_expr = true | ||
reorder_imports = true | ||
trailing_comma = "Vertical" | ||
version = "Two" | ||
where_single_line = true | ||
wrap_comments = true |
Oops, something went wrong.