diff --git a/benches/parse.rs b/benches/parse.rs index e6f0a55..4549d95 100644 --- a/benches/parse.rs +++ b/benches/parse.rs @@ -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); diff --git a/development.md b/development.md index df8e8c7..2810a48 100644 --- a/development.md +++ b/development.md @@ -27,6 +27,8 @@ cargo fuzz run fuzz_target_1 ```shell curl -q https://orgmode.org/worg/doc.org --output ./benches/doc.org curl -q https://orgmode.org/worg/org-faq.org --output ./benches/org-faq.org +curl -q https://orgmode.org/worg/org-hacks.org --output ./benches/org-hacks.org +curl -q https://orgmode.org/worg/org-release-notes.org --output ./benches/org-release-notes.org curl -q https://orgmode.org/worg/org-syntax.org --output ./benches/org-syntax.org cargo bench --bench parse diff --git a/examples/parse.rs b/examples/parse.rs index c272fd5..978371d 100644 --- a/examples/parse.rs +++ b/examples/parse.rs @@ -23,8 +23,8 @@ fn main() { if args.len() < 2 { eprintln!("Usage: {} ", args[0]); } else { - let s = &args[1].replace(r#"\n"#, "\n").replace(r#"\r"#, "\r"); - let org = Org::parse(&s); + let s = &args[1].replace(r"\n", "\n").replace(r"\r", "\r"); + let org = Org::parse(s); println!("{:#?}", org.document().syntax()); } }