From 70262145855e2a254663042f01843bb079307db6 Mon Sep 17 00:00:00 2001 From: Jack Thomson Date: Fri, 11 Nov 2022 15:13:58 +0000 Subject: [PATCH] Tidy up features and remove un-needed branching --- .github/workflows/rust.yml | 7 +++---- Cargo.toml | 6 +----- README.md | 24 +++++------------------- src/counter.rs | 12 ++---------- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0eaf0a3..748d8a4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,10 +19,9 @@ jobs: steps: - uses: hecrj/setup-rust-action@v1 - with: - rust-version: nightly + rust-version: stable - uses: actions/checkout@v3 - name: Build - run: cargo build --verbose --features nightly + run: cargo build --verbose - name: Run tests - run: cargo test --verbose --features nightly + run: cargo test --verbose diff --git a/Cargo.toml b/Cargo.toml index 5000e47..2be67e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,6 @@ repository = "https://github.com/JackThomson2/fast-counter" rayon = "1.3" criterion = "0.3" -[features] -default = [] -nightly = [] - [[bench]] name = "incrementer" harness = false @@ -26,4 +22,4 @@ harness = false panic = "abort" opt-level = 3 codegen-units = 1 -lto = "fat" \ No newline at end of file +lto = "fat" diff --git a/README.md b/README.md index cf0db8c..dec477d 100644 --- a/README.md +++ b/README.md @@ -19,31 +19,17 @@ atomic_counter/16 time: [410.49 us 411.71 us 412.99 us] ------------------------------------------------------------------------------ -fast_counter_nightly/2 time: [264.99 us 267.24 us 269.14 us] - thrpt: [121.75 Melem/s 122.61 Melem/s 123.66 Melem/s] - -fast_counter_nightly/4 time: [252.67 us 255.30 us 257.85 us] - thrpt: [127.08 Melem/s 128.35 Melem/s 129.68 Melem/s] - -fast_counter_nightly/8 time: [193.19 us 197.00 us 200.92 us] - thrpt: [163.09 Melem/s 166.34 Melem/s 169.62 Melem/s] - -fast_counter_nightly/16 time: [154.45 us 159.36 us 164.75 us] - thrpt: [198.90 Melem/s 205.63 Melem/s 212.16 Melem/s] - ------------------------------------------------------------------------------- - -fast_counter_stable/2 time: [299.28 us 300.40 us 301.52 us] +fast_counter/2 time: [299.28 us 300.40 us 301.52 us] thrpt: [108.68 Melem/s 109.08 Melem/s 109.49 Melem/s] -fast_counter_stable/4 time: [276.78 us 278.90 us 281.02 us] +fast_counter/4 time: [276.78 us 278.90 us 281.02 us] thrpt: [116.61 Melem/s 117.49 Melem/s 118.39 Melem/s] -fast_counter_stable/8 time: [194.94 us 199.44 us 204.17 us] +fast_counter/8 time: [194.94 us 199.44 us 204.17 us] thrpt: [160.49 Melem/s 164.30 Melem/s 168.10 Melem/s] -fast_counter_stable/16 time: [152.30 us 155.98 us 159.92 us] +fast_counter/16 time: [152.30 us 155.98 us 159.92 us] thrpt: [204.91 Melem/s 210.08 Melem/s 215.16 Melem/s] ``` -Big shoutout to @jimvdl who put the core starting point for this together \ No newline at end of file +Big shoutout to @jimvdl who put the core starting point for this together diff --git a/src/counter.rs b/src/counter.rs index f76f863..a4cbab8 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -10,7 +10,7 @@ pub struct ConcurrentCounter { static THREAD_COUNTER: AtomicUsize = AtomicUsize::new(1); thread_local! { - static THREAD_ID: Cell = Cell::new(0); + static THREAD_ID: Cell = Cell::new(THREAD_COUNTER.fetch_add(1, Ordering::SeqCst)); } impl ConcurrentCounter { @@ -28,15 +28,7 @@ impl ConcurrentCounter { #[inline] fn thread_id(&self) -> usize { THREAD_ID.with(|id| { - match id.get() { - 0 => { - let new_id = THREAD_COUNTER.fetch_add(1, Ordering::SeqCst); - id.set(new_id); - - new_id - }, - i => i - } + id.get() }) }