Skip to content

Commit

Permalink
Benchmarking with criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
simsekgokhan committed Feb 15, 2024
1 parent 99ecf18 commit 69b0099
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ serde_derive = "1"
serde_json = "1"
tokio = { version = "1.23.0", features = ["full"] }

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }

[[bench]]
name = "my_benchmark"
harness = false

[workspace]
members = [
"src/adder",
Expand Down
16 changes: 16 additions & 0 deletions benches/my_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn fibonacci(n: u64) -> u64 {
match n {
0 => 1,
1 => 1,
n => fibonacci(n-1) + fibonacci(n-2),
}
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 69b0099

Please sign in to comment.