From d41cd5784705453cba820ac0875f6704b16d956d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Fri, 13 Mar 2026 07:40:21 +0100 Subject: [PATCH] Add asting benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- Cargo.toml | 4 ++++ benches/asting.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 benches/asting.rs diff --git a/Cargo.toml b/Cargo.toml index f93866f..fe1e716 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,10 @@ edition = "2024" name = "parsing" harness = false +[[bench]] +name = "asting" +harness = false + [profile.bench] debug = true diff --git a/benches/asting.rs b/benches/asting.rs new file mode 100644 index 0000000..1528069 --- /dev/null +++ b/benches/asting.rs @@ -0,0 +1,54 @@ +use criterion::BenchmarkId; +use criterion::Criterion; +use criterion::criterion_group; +use criterion::criterion_main; +use nomo::input::NomoInput; + +fn asting_benchmark(c: &mut Criterion) { + let mut parsing = c.benchmark_group("Asting"); + + for size in [1, 10, 200, 1000] { + let mut input = String::new(); + + for _ in 0..size { + input.push_str("{{ if foo }}{{= variable }}{{ end }}"); + } + + let input = NomoInput::from(input); + + parsing.throughput(criterion::Throughput::Bytes(input.len() as u64)); + parsing.bench_with_input(BenchmarkId::from_parameter(size), &input, |b, input| { + b.iter(|| { + let tokens = nomo::parser::parse(input.clone()).unwrap(); + let _ast = nomo::ast::parse(tokens.tokens()).unwrap(); + }); + }); + } +} + +fn asting_nested(c: &mut Criterion) { + let mut parsing = c.benchmark_group("Asting"); + + for size in [1, 2, 8, 12] { + let mut input = String::new(); + + for _ in 0..size { + input = format!( + "{{{{ for foo in bar }}}} {input} {{{{ if foo }}}} Hi! {input} {{{{ end }}}} Yooo {{{{ end }}}}" + ); + } + + let input = NomoInput::from(input); + + parsing.throughput(criterion::Throughput::Bytes(input.len() as u64)); + parsing.bench_with_input(BenchmarkId::from_parameter(size), &input, |b, input| { + b.iter(|| { + let tokens = nomo::parser::parse(input.clone()).unwrap(); + let _ast = nomo::ast::parse(tokens.tokens()).unwrap(); + }); + }); + } +} + +criterion_group!(benches, asting_benchmark, asting_nested); +criterion_main!(benches);