Skip to content

Commit d80edf2

Browse files
committed
refactor: rework as fastant
Signed-off-by: tison <[email protected]>
1 parent 0c5b096 commit d80edf2

File tree

9 files changed

+141
-135
lines changed

9 files changed

+141
-135
lines changed

.github/workflows/ci.yml

+24-24
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main ]
88

99
env:
1010
CARGO_TERM_COLOR: always
@@ -14,36 +14,36 @@ jobs:
1414
runs-on: ${{ matrix.os }}
1515
strategy:
1616
matrix:
17-
os: [macos-latest, ubuntu-latest, windows-latest]
18-
features: ["atomic", "atomic,fallback-coarse"]
19-
rust: [stable]
17+
os: [ macos-latest, ubuntu-latest, windows-latest ]
18+
features: [ "atomic", "atomic,fallback-coarse" ]
19+
rust: [ stable ]
2020
env:
2121
RUST_BACKTRACE: 1
2222
steps:
23-
- uses: actions/checkout@v2
24-
- name: Set up toolchains
25-
uses: actions-rs/toolchain@v1
26-
with:
23+
- uses: actions/checkout@v4
24+
- uses: Swatinem/rust-cache@v2
25+
- name: Set up toolchains
26+
uses: dtolnay/rust-toolchain@master
27+
with:
2728
toolchain: ${{ matrix.rust }}
28-
override: true
2929
components: rustfmt, clippy
30-
- name: Check format
31-
run: cargo fmt --all -- --check
32-
- name: Build
33-
run: cargo build --workspace --all-targets --features ${{ matrix.features }}
34-
- name: Clippy
35-
run: cargo clippy --workspace --all-targets --features ${{ matrix.features }} -- -D warnings
36-
- name: Run tests
37-
run: cargo test --workspace --all-targets --features ${{ matrix.features }} -- --nocapture
38-
- name: Run benches
39-
run: cargo bench --workspace --all-targets --features ${{ matrix.features }}
30+
- name: Check format
31+
run: cargo fmt --all -- --check
32+
- name: Build
33+
run: cargo build --workspace --all-targets --features ${{ matrix.features }}
34+
- name: Clippy
35+
run: cargo clippy --workspace --all-targets --features ${{ matrix.features }} -- -D warnings
36+
- name: Run tests
37+
run: cargo test --workspace --all-targets --features ${{ matrix.features }} -- --nocapture
38+
- name: Run benches
39+
run: cargo bench --workspace --all-targets --features ${{ matrix.features }}
4040

4141
build-wasm:
4242
runs-on: ubuntu-latest
4343
env:
4444
RUST_BACKTRACE: 1
4545
steps:
46-
- uses: actions/checkout@v2
47-
- name: Set up toolchains
48-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
49-
- run: wasm-pack test --node
46+
- uses: actions/checkout@v4
47+
- name: Set up toolchains
48+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
49+
- run: wasm-pack test --node

Cargo.toml

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
[package]
2-
name = "minstant"
3-
version = "0.1.7"
4-
authors = ["The TiKV Authors"]
2+
name = "fastant"
3+
version = "0.1.0"
4+
authors = ["FastLabs Developers"]
55
edition = "2021"
66
license = "MIT"
7-
description = "A drop-in replacement for `std::time::Instant` that measures time with high performance and high accuracy powered by TSC"
8-
homepage = "https://github.com/tikv/minstant"
9-
repository = "https://github.com/tikv/minstant"
10-
documentation = "https://docs.rs/minstant"
7+
description = "A drop-in replacement for `std::time::Instant` that measures time with high performance and high accuracy powered by Time Stamp Counter (TSC)."
8+
homepage = "https://github.com/fast/fastant"
9+
repository = "https://github.com/fast/fastant"
10+
documentation = "https://docs.rs/fastant"
1111
readme = "README.md"
1212
keywords = ["TSC", "clock", "rdtsc", "timing", "nanosecond"]
13+
1314
[package.metadata.docs.rs]
1415
all-features = true
1516
rustdoc-args = ["--cfg", "docsrs"]
1617

1718
[dependencies]
18-
ctor = "0.1.20"
19+
ctor = "0.2"
1920
coarsetime = { version = "0.1", optional = true }
2021
web-time = "1.0"
2122

@@ -24,8 +25,8 @@ atomic = []
2425
fallback-coarse = ["coarsetime"]
2526

2627
[dev-dependencies]
27-
criterion = "0.3"
28-
quanta = "0.9"
28+
criterion = "0.5"
29+
quanta = "0.12"
2930
rand = "0.8"
3031
wasm-bindgen-test = "0.3"
3132
getrandom = { version = "0.2", features = ["js"] }

README.md

+15-33
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
1-
# minstant
2-
[![Actions Status](https://github.com/tikv/minstant/workflows/CI/badge.svg)](https://github.com/tikv/minstant/actions)
3-
[![Build Status](https://travis-ci.org/tikv/minstant.svg?branch=master)](https://travis-ci.org/tikv/minstant)
4-
[![Documentation](https://docs.rs/minstant/badge.svg)](https://docs.rs/minstant/)
5-
[![Crates.io](https://img.shields.io/crates/v/minstant.svg)](https://crates.io/crates/minstant)
6-
[![LICENSE](https://img.shields.io/github/license/tikv/minstant.svg)](https://github.com/tikv/minstant/blob/master/LICENSE)
1+
# Fastant
72

8-
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).
3+
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).
4+
5+
[![Actions Status](https://github.com/fast/fastant/workflows/CI/badge.svg)](https://github.com/fast/fastant/actions)
6+
[![Documentation](https://docs.rs/fastant/badge.svg)](https://docs.rs/fastant/)
7+
[![Crates.io](https://img.shields.io/crates/v/fastant.svg)](https://crates.io/crates/fastant)
8+
[![LICENSE](https://img.shields.io/github/license/fast/fastant.svg)](LICENSE)
99

1010
## Usage
1111

1212
```toml
1313
[dependencies]
14-
minstant = "0.1"
14+
fastant = "0.1"
1515
```
1616

1717
```rust
18-
let start = minstant::Instant::now();
19-
20-
// Code snipppet to measure
21-
22-
let duration: std::time::Duration = start.elapsed();
18+
fn main() {
19+
let start = fastant::Instant::now();
20+
let duration: std::time::Duration = start.elapsed();
21+
}
2322
```
2423

25-
2624
## Motivation
2725

28-
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.
26+
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.
2927

3028
## Platform Support
3129

32-
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`.
30+
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`.
3331

3432
If speed is privileged over accuracy when fallback occurs, you can use `fallback-coarse` feature to use coarse time:
3533

3634
```toml
3735
[dependencies]
38-
minstant = { version = "0.1", features = ["fallback-coarse"] }
39-
```
40-
41-
## Benchmark
42-
43-
Benchmark platform is `Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz` on CentOS 7.
44-
45-
```sh
46-
> cargo criterion
47-
48-
Instant::now()/minstant time: [10.449 ns 10.514 ns 10.619 ns]
49-
Instant::now()/quanta time: [31.467 ns 31.628 ns 31.822 ns]
50-
Instant::now()/std time: [26.831 ns 26.924 ns 27.016 ns]
51-
minstant::Anchor::new() time: [46.987 ns 47.243 ns 47.498 ns]
52-
minstant::Instant::as_unix_nanos() time: [15.287 ns 15.318 ns 15.350 ns]
36+
fastant = { version = "0.1", features = ["fallback-coarse"] }
5337
```
54-
55-
![Benchmark](benchmark.jpeg)

benches/criterion.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use criterion::{black_box, criterion_group, criterion_main, Criterion};
22

3-
fn bench_nows(c: &mut Criterion) {
4-
// The first call will take some time for calibartion
3+
fn bench_now(c: &mut Criterion) {
4+
// The first call will take some time for calibration
55
quanta::Instant::now();
66

77
let mut group = c.benchmark_group("Instant::now()");
8-
group.bench_function("minstant", |b| {
9-
b.iter(minstant::Instant::now);
8+
group.bench_function("fastant", |b| {
9+
b.iter(fastant::Instant::now);
1010
});
1111
group.bench_function("quanta", |b| {
1212
b.iter(quanta::Instant::now);
@@ -18,19 +18,19 @@ fn bench_nows(c: &mut Criterion) {
1818
}
1919

2020
fn bench_anchor_new(c: &mut Criterion) {
21-
c.bench_function("minstant::Anchor::new()", |b| {
22-
b.iter(minstant::Anchor::new);
21+
c.bench_function("fastant::Anchor::new()", |b| {
22+
b.iter(fastant::Anchor::new);
2323
});
2424
}
2525

2626
fn bench_as_unix_nanos(c: &mut Criterion) {
27-
let anchor = minstant::Anchor::new();
28-
c.bench_function("minstant::Instant::as_unix_nanos()", |b| {
27+
let anchor = fastant::Anchor::new();
28+
c.bench_function("fastant::Instant::as_unix_nanos()", |b| {
2929
b.iter(|| {
30-
black_box(minstant::Instant::now().as_unix_nanos(&anchor));
30+
black_box(fastant::Instant::now().as_unix_nanos(&anchor));
3131
});
3232
});
3333
}
3434

35-
criterion_group!(benches, bench_nows, bench_anchor_new, bench_as_unix_nanos);
35+
criterion_group!(benches, bench_now, bench_anchor_new, bench_as_unix_nanos);
3636
criterion_main!(benches);

benchmark.jpeg

-121 KB
Binary file not shown.

rustfmt.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
comment_width = 120
2+
edition = "2021"
3+
format_code_in_doc_comments = true
4+
group_imports = "StdExternalCrate"
5+
imports_granularity = "Item"
6+
normalize_comments = true
7+
overflow_delimited_expr = true
8+
reorder_imports = true
9+
trailing_comma = "Vertical"
10+
version = "Two"
11+
where_single_line = true
12+
wrap_comments = true

0 commit comments

Comments
 (0)