Skip to content

Commit

Permalink
give a fault bench
Browse files Browse the repository at this point in the history
  • Loading branch information
ccqpein committed May 14, 2023
1 parent 2310ff1 commit ed13f0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rusty/benchmark-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ pprof = { version = "0.11.1", features = ["flamegraph", "criterion"] }
[[bench]]
name = "bench0"
harness = false

[[bench]]
name = "bench-fault"
harness = false
21 changes: 21 additions & 0 deletions rusty/benchmark-demo/benches/bench-fault.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use pprof::criterion::{Output, PProfProfiler};

fn format_macro(v: i32) -> String {
format!("{}", v)
}

fn bench_format_macro(c: &mut Criterion) {
let a = 1;
c.bench_function("bench_format_macro", |b| {
b.iter(|| format_macro(black_box(a.clone())))
});
}

criterion_group! {
name = bench_fault;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = bench_format_macro,
}

criterion_main!(bench_fault);

0 comments on commit ed13f0d

Please sign in to comment.