add criterion benchmarks
This commit is contained in:
parent
6ce49e1a71
commit
4f0be0c265
4 changed files with 436 additions and 0 deletions
14
bench/criterion/Cargo.toml
Normal file
14
bench/criterion/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "bench-crit"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.4", default-features = false }
|
||||
bench-input = { path = "../input" }
|
||||
jotdown = { path = "../../" }
|
||||
|
||||
[[bench]]
|
||||
name = "criterion"
|
||||
path = "main.rs"
|
||||
harness = false
|
86
bench/criterion/main.rs
Normal file
86
bench/criterion/main.rs
Normal file
|
@ -0,0 +1,86 @@
|
|||
use criterion::criterion_group;
|
||||
use criterion::criterion_main;
|
||||
|
||||
use jotdown::Render;
|
||||
|
||||
fn gen_block(c: &mut criterion::Criterion) {
|
||||
let mut group = c.benchmark_group("block");
|
||||
for (name, input) in bench_input::INPUTS {
|
||||
group.throughput(criterion::Throughput::Bytes(input.len() as u64));
|
||||
group.bench_with_input(
|
||||
criterion::BenchmarkId::from_parameter(name),
|
||||
input,
|
||||
|b, &input| {
|
||||
b.iter(|| jotdown::Parser::new(input));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
criterion_group!(block, gen_block);
|
||||
|
||||
fn gen_inline(c: &mut criterion::Criterion) {
|
||||
let mut group = c.benchmark_group("inline");
|
||||
for (name, input) in bench_input::INPUTS {
|
||||
group.throughput(criterion::Throughput::Bytes(input.len() as u64));
|
||||
group.bench_with_input(
|
||||
criterion::BenchmarkId::from_parameter(name),
|
||||
input,
|
||||
|b, &input| {
|
||||
b.iter_batched(
|
||||
|| jotdown::Parser::new(input),
|
||||
|p| p.last().unwrap(),
|
||||
criterion::BatchSize::SmallInput,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
criterion_group!(inline, gen_inline);
|
||||
|
||||
fn gen_html(c: &mut criterion::Criterion) {
|
||||
let mut group = c.benchmark_group("html");
|
||||
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.push(p.into_iter(), &mut s).unwrap();
|
||||
s
|
||||
},
|
||||
criterion::BatchSize::SmallInput,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
criterion_group!(html, gen_html);
|
||||
|
||||
fn gen_full(c: &mut criterion::Criterion) {
|
||||
let mut group = c.benchmark_group("full");
|
||||
for (name, input) in bench_input::INPUTS {
|
||||
group.throughput(criterion::Throughput::Bytes(input.len() as u64));
|
||||
group.bench_with_input(
|
||||
criterion::BenchmarkId::from_parameter(name),
|
||||
input,
|
||||
|b, &input| {
|
||||
b.iter_with_large_drop(|| {
|
||||
let mut s = String::new();
|
||||
jotdown::html::Renderer
|
||||
.push(jotdown::Parser::new(input), &mut s)
|
||||
.unwrap();
|
||||
s
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
criterion_group!(full, gen_full);
|
||||
|
||||
criterion_main!(block, inline, html, full);
|
Loading…
Add table
Add a link
Reference in a new issue