bench-crit: add html_borrow, html_clone

allow comparing between rendering owned, borrowed or cloned events
This commit is contained in:
Noah Hellman 2023-03-21 22:31:49 +01:00
parent 10788af246
commit 5daa160288

View file

@ -64,6 +64,60 @@ fn gen_html(c: &mut criterion::Criterion) {
}
criterion_group!(html, gen_html);
fn gen_html_borrow(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("html_borrow");
for (name, input) in bench_input::INPUTS {
group.throughput(criterion::Throughput::Elements(
jotdown::Parser::new(input).count() as u64,
));
group.bench_with_input(
criterion::BenchmarkId::from_parameter(name),
input,
|b, &input| {
b.iter_batched(
|| jotdown::Parser::new(input).collect::<Vec<_>>(),
|p| {
let mut s = String::new();
jotdown::html::Renderer::default()
.push_borrowed(p.as_slice().iter(), &mut s)
.unwrap();
s
},
criterion::BatchSize::SmallInput,
);
},
);
}
}
criterion_group!(html_borrow, gen_html_borrow);
fn gen_html_clone(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("html_clone");
for (name, input) in bench_input::INPUTS {
group.throughput(criterion::Throughput::Elements(
jotdown::Parser::new(input).count() as u64,
));
group.bench_with_input(
criterion::BenchmarkId::from_parameter(name),
input,
|b, &input| {
b.iter_batched(
|| jotdown::Parser::new(input).collect::<Vec<_>>(),
|p| {
let mut s = String::new();
jotdown::html::Renderer::default()
.push(p.iter().cloned(), &mut s)
.unwrap();
s
},
criterion::BatchSize::SmallInput,
);
},
);
}
}
criterion_group!(html_clone, gen_html_clone);
fn gen_full(c: &mut criterion::Criterion) {
let mut group = c.benchmark_group("full");
for (name, input) in bench_input::INPUTS {
@ -85,4 +139,4 @@ fn gen_full(c: &mut criterion::Criterion) {
}
criterion_group!(full, gen_full);
criterion_main!(block, inline, html, full);
criterion_main!(block, inline, html, html_borrow, html_clone, full);