Skip to content

Commit

Permalink
fix: add more opaque black boxes in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
art049 committed Jul 25, 2023
1 parent 9b955a7 commit ac7e208
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion};
use codspeed_criterion_compat::{black_box, criterion_group, BenchmarkId, Criterion};

fn fibonacci_slow(n: u64) -> u64 {
match n {
Expand Down Expand Up @@ -27,14 +27,16 @@ fn fibonacci_fast(n: u64) -> u64 {
fn compare_fibonaccis(c: &mut Criterion) {
let mut group = c.benchmark_group("Fibonacci");

group.bench_with_input("Recursive", &20, |b, i| b.iter(|| fibonacci_slow(*i)));
group.bench_with_input("Recursive", &20, |b, i| {
b.iter(|| fibonacci_slow(black_box(*i)))
});
group.bench_with_input("Iterative", &20, |b, i| b.iter(|| fibonacci_fast(*i)));
}
fn compare_fibonaccis_group(c: &mut Criterion) {
let mut group = c.benchmark_group("Fibonacci3");
for i in 20..=21 {
group.bench_with_input(BenchmarkId::new("Recursive", i), &i, |b, i| {
b.iter(|| fibonacci_slow(*i))
b.iter(|| fibonacci_slow(black_box(*i)))
});
group.bench_with_input(BenchmarkId::new("Iterative", i), &i, |b, i| {
b.iter(|| fibonacci_fast(*i))
Expand Down

0 comments on commit ac7e208

Please sign in to comment.