extern crate criterion;
use criterion::{
criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration,
SamplingMode,
};
use pprof::criterion::{Output, PProfProfiler};
use rope_bench::{StringContainerA, StringContainerB};
use std::time::Duration;
fn benchmark_a(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("Formatters");
let test_cases: Vec<String> = [
"q9w83nurapw9e8urn3v ejf 0394 jadsaaewr gt54 3r",
"039q84nc09r8ewru0f94aw948h5n-9q3849v",
"39-48mu5f-9834u-5um0u-09e8 r9-g8hj e4tv[we ",
"nj90 834ng0w98unrf pjsznd-9854n posaein -4598nsae ",
"9083 4[o0wi9me30948jan=09w4nj3498h aosindm f=0WNJG [ODIFNGH;X",
"09w458thm0wv9e4hytn0w45t09w834u0q9w348mcr0q9384",
"0r7830h84hct09843 0-q9384ht 0q98h408nqf0-483 nfq0-38q9w34e h-q034hr- q29h83 t05q3gbt",
"0-q984 3htfiefdn-w9e3- tq934q-eru n",
"09w 834ehnfidunv -0394 320pfuqn3-94 qnfoasidng kjbn =293",
" fornq=934 nhfpowerdn [aogtbh943q gas;kdnq =0384hj f0H4G -=Q9438THG [O"
].iter().map(|a| a.to_string()).collect();
let test_case_a = StringContainerA(test_cases.clone());
let test_case_b = StringContainerB(test_cases.clone());
group
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic))
.sampling_mode(SamplingMode::Linear);
group.bench_with_input(
BenchmarkId::new("StringContainerA", String::from("")),
&test_cases,
|bencher, _| bencher.iter(|| {
format!("{}", test_case_a);
}),
);
group.bench_with_input(
BenchmarkId::new("StringContainerB", String::from("")),
&test_cases,
|bencher, _| bencher.iter(|| {
format!("{}", test_case_b);
}),
);
group.finish();
}
criterion_group! {
name = benchmarks;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))).sample_size(100).warm_up_time(Duration::new(3, 0)).measurement_time(Duration::new(5, 0)).significance_level(0.05).with_plots();
targets = benchmark_a
}
criterion_main!(benchmarks);