diff --git a/rusty/benchmark-demo/Cargo.toml b/rusty/benchmark-demo/Cargo.toml index f29945b..6fdb9ea 100644 --- a/rusty/benchmark-demo/Cargo.toml +++ b/rusty/benchmark-demo/Cargo.toml @@ -15,3 +15,7 @@ pprof = { version = "0.11.1", features = ["flamegraph", "criterion"] } [[bench]] name = "bench0" harness = false + +[[bench]] +name = "bench-fault" +harness = false diff --git a/rusty/benchmark-demo/benches/bench-fault.rs b/rusty/benchmark-demo/benches/bench-fault.rs new file mode 100644 index 0000000..4ba9ec8 --- /dev/null +++ b/rusty/benchmark-demo/benches/bench-fault.rs @@ -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);