From 369d3e8c502b4134af5b31f9ad82cd7abaabd79d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 17 Oct 2023 10:57:04 -0400 Subject: [PATCH] Add a full-document parse benchmark. --- scripts/perf.bash | 2 +- src/parser/document.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/perf.bash b/scripts/perf.bash index aa7ae32..fab93e7 100755 --- a/scripts/perf.bash +++ b/scripts/perf.bash @@ -14,7 +14,7 @@ function main { additional_flags+=(--profile "$PROFILE") fi (cd "$DIR/../" && cargo build --no-default-features "${additional_flags[@]}") - perf record --freq=2000 --call-graph dwarf --output="$DIR/../perf.data" "$DIR/../target/${PROFILE}/parse" "${@}" + perf record --freq=70000 --call-graph dwarf --output="$DIR/../perf.data" "$DIR/../target/${PROFILE}/parse" "${@}" # Convert to a format firefox will read # flags to consider --show-info diff --git a/src/parser/document.rs b/src/parser/document.rs index a2122d3..898b42e 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -208,3 +208,17 @@ fn _document<'b, 'g, 'r, 's>( }, )) } + +#[cfg(test)] +mod tests { + use test::Bencher; + + use super::*; + + #[bench] + fn bench_full_document(b: &mut Bencher) { + let input = include_str!("../../org_mode_samples/element_container_priority/README.org"); + + b.iter(|| assert!(parse(input).is_ok())); + } +}