Skip to content

Commit

Permalink
Tidy up features and remove un-needed branching
Browse files Browse the repository at this point in the history
  • Loading branch information
JackThomson2 committed Nov 11, 2022
1 parent b5a696b commit 7026214
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 38 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,4 +22,4 @@ harness = false
panic = "abort"
opt-level = 3
codegen-units = 1
lto = "fat"
lto = "fat"
24 changes: 5 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Big shoutout to @jimvdl who put the core starting point for this together
12 changes: 2 additions & 10 deletions src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct ConcurrentCounter {
static THREAD_COUNTER: AtomicUsize = AtomicUsize::new(1);

thread_local! {
static THREAD_ID: Cell<usize> = Cell::new(0);
static THREAD_ID: Cell<usize> = Cell::new(THREAD_COUNTER.fetch_add(1, Ordering::SeqCst));
}

impl ConcurrentCounter {
Expand All @@ -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()
})
}

Expand Down

0 comments on commit 7026214

Please sign in to comment.