forked from tikv/pprof-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
criterion.rs
36 lines (29 loc) · 960 Bytes
/
criterion.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#[macro_use]
extern crate criterion;
use criterion::{black_box, BenchmarkId, Criterion};
use pprof::criterion::{Output, PProfProfiler};
// Thanks to the example provided by @jebbow in his article
// https://www.jibbow.com/posts/criterion-flamegraphs/
fn fibonacci(n: u64) -> u64 {
match n {
0 | 1 => 1,
n => fibonacci(n - 1) + fibonacci(n - 2),
}
}
fn bench(c: &mut Criterion) {
c.bench_function("Fibonacci", |b| b.iter(|| fibonacci(black_box(20))));
}
fn bench_group(c: &mut Criterion) {
let mut group = c.benchmark_group("Fibonacci Sizes");
for s in &[1, 10, 100, 1000] {
group.bench_with_input(BenchmarkId::from_parameter(s), s, |b, s| {
b.iter(|| fibonacci(black_box(*s)))
});
}
}
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = bench, bench_group
}
criterion_main!(benches);