diff --git a/Cargo.toml b/Cargo.toml index ea9f770..8a5cf83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/benches/my_benchmark.rs b/benches/my_benchmark.rs new file mode 100644 index 0000000..81516fb --- /dev/null +++ b/benches/my_benchmark.rs @@ -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); \ No newline at end of file