Skip to content

Commit 522bad3

Browse files
committed
bench: gate all num-primes benchmarks behind feature flag
num-primes uses thread_rng() internally, making its benchmarks non-deterministic. CodSpeed's instruction-counting simulation amplifies this into huge false regressions. Gate all num-primes bench_functions with #[cfg(feature = "num-primes")] and build without the feature in CodSpeed CI.
1 parent 4526187 commit 522bad3

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/codspeed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
bins: cargo-codspeed
3232

3333
- name: Build the benchmark target(s)
34-
run: cargo codspeed build -m ${{ matrix.mode }} -p num-prime-bench
34+
run: cargo codspeed build -m ${{ matrix.mode }} -p num-prime-bench --no-default-features
3535

3636
- name: Run the benchmarks
3737
uses: CodSpeedHQ/action@v4

bench/benches/bench.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub fn bench_is_prime(c: &mut Criterion) {
6060
.count()
6161
})
6262
});
63+
#[cfg(feature = "num-primes")]
6364
group.bench_function("num-primes", |b| {
6465
b.iter(|| {
6566
numbers
@@ -87,6 +88,7 @@ pub fn bench_is_prime(c: &mut Criterion) {
8788
.count()
8889
})
8990
});
91+
#[cfg(feature = "num-primes")]
9092
group.bench_function("num-primes", |b| {
9193
b.iter(|| {
9294
numbers
@@ -126,6 +128,7 @@ pub fn bench_is_prime(c: &mut Criterion) {
126128
.count()
127129
})
128130
});
131+
#[cfg(feature = "num-primes")]
129132
group.bench_function("num-primes", |b| {
130133
b.iter(|| {
131134
numbers
@@ -153,6 +156,7 @@ pub fn bench_is_prime(c: &mut Criterion) {
153156
.count()
154157
})
155158
});
159+
#[cfg(feature = "num-primes")]
156160
group.bench_function("num-primes", |b| {
157161
b.iter(|| {
158162
numbers
@@ -208,6 +212,7 @@ pub fn bench_prime_gen(c: &mut Criterion) {
208212
b.iter(|| -> num_bigint::BigUint { rng.gen_prime(256, None) })
209213
});
210214
// Note: num-primes uses thread_rng() internally, so this benchmark is not deterministic
215+
#[cfg(feature = "num-primes")]
211216
group.bench_function("num-primes", |b| b.iter(|| Generator::new_prime(256)));
212217
let mut rng_gp = ChaCha8Rng::seed_from_u64(257);
213218
group.bench_function("glass_pumpkin", |b| {
@@ -223,6 +228,7 @@ pub fn bench_prime_gen(c: &mut Criterion) {
223228
b.iter(|| -> num_bigint::BigUint { rng.gen_safe_prime(256) })
224229
});
225230
// Note: num-primes uses thread_rng() internally, so this benchmark is not deterministic
231+
#[cfg(feature = "num-primes")]
226232
group.bench_function("num-primes", |b| b.iter(|| Generator::safe_prime(256)));
227233
let mut rng_gp = ChaCha8Rng::seed_from_u64(513);
228234
group.bench_function("glass_pumpkin", |b| {

0 commit comments

Comments
 (0)