chore: update benchmark

This commit is contained in:
PoiScript 2023-11-24 10:58:08 +08:00
parent 471a23c958
commit be32dc24e0
No known key found for this signature in database
GPG key ID: 22C2B1249D99985E
3 changed files with 26 additions and 9 deletions

View file

@ -1,24 +1,39 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use orgize::Org;
const INPUT: &[(&str, &str)] = &[
("doc.org", include_str!("./doc.org")),
("org-faq.org", include_str!("./org-faq.org")),
("org-hacks.org", include_str!("./org-hacks.org")),
(
"org-release-notes.org",
include_str!("./org-release-notes.org"),
),
("org-syntax.org", include_str!("./org-syntax.org")),
];
pub fn bench_parse(c: &mut Criterion) {
let mut group = c.benchmark_group("Parse");
let mut group = c.benchmark_group("Org::parse");
for (id, json) in INPUT.iter() {
group.bench_with_input(BenchmarkId::new("Rowan", id), json, |b, i| {
b.iter(|| Org::parse(i))
});
for (id, org) in INPUT {
group.throughput(Throughput::Bytes(org.len() as u64));
group.bench_with_input(*id, org, |b, i| b.iter(|| Org::parse(i)));
}
group.finish();
}
criterion_group!(benches, bench_parse);
pub fn bench_to_html(c: &mut Criterion) {
let mut group = c.benchmark_group("Org::to_html");
for (id, org) in INPUT {
group.throughput(Throughput::Bytes(org.len() as u64));
group.bench_with_input(*id, &Org::parse(org), |b, i| b.iter(|| i.to_html()));
}
group.finish();
}
criterion_group!(benches, bench_parse, bench_to_html);
criterion_main!(benches);