Zernit/benches/example_bench.rs

22 lines
536 B
Rust
Raw Permalink Normal View History

2020-02-09 16:29:08 +01:00
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2020-02-10 18:41:28 +01:00
/*
This is base benchmark made for consistency
FIXME-BENCH: Make cargo to recognize `benches/rustlang` path instead of `benches/`
*/
2020-02-09 16:29:08 +01:00
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);