Skip to content

Commit ac7e208

Browse files
committed
fix: add more opaque black boxes in the tests
1 parent 9b955a7 commit ac7e208

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/criterion_compat/benches/criterion_integration/compare_functions.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion};
1+
use codspeed_criterion_compat::{black_box, criterion_group, BenchmarkId, Criterion};
22

33
fn fibonacci_slow(n: u64) -> u64 {
44
match n {
@@ -27,14 +27,16 @@ fn fibonacci_fast(n: u64) -> u64 {
2727
fn compare_fibonaccis(c: &mut Criterion) {
2828
let mut group = c.benchmark_group("Fibonacci");
2929

30-
group.bench_with_input("Recursive", &20, |b, i| b.iter(|| fibonacci_slow(*i)));
30+
group.bench_with_input("Recursive", &20, |b, i| {
31+
b.iter(|| fibonacci_slow(black_box(*i)))
32+
});
3133
group.bench_with_input("Iterative", &20, |b, i| b.iter(|| fibonacci_fast(*i)));
3234
}
3335
fn compare_fibonaccis_group(c: &mut Criterion) {
3436
let mut group = c.benchmark_group("Fibonacci3");
3537
for i in 20..=21 {
3638
group.bench_with_input(BenchmarkId::new("Recursive", i), &i, |b, i| {
37-
b.iter(|| fibonacci_slow(*i))
39+
b.iter(|| fibonacci_slow(black_box(*i)))
3840
});
3941
group.bench_with_input(BenchmarkId::new("Iterative", i), &i, |b, i| {
4042
b.iter(|| fibonacci_fast(*i))

0 commit comments

Comments
 (0)