From 474324726a740e1576a0b7b1930448d1d14564af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Wed, 11 Mar 2026 18:39:57 +0100 Subject: [PATCH] Add fuzzer for deeply nested parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcel Müller --- benches/parsing.rs | 23 ++++++++++++++++++++++- fuzz/Cargo.lock | 2 -- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/benches/parsing.rs b/benches/parsing.rs index f7e3da0..35de7ae 100644 --- a/benches/parsing.rs +++ b/benches/parsing.rs @@ -23,5 +23,26 @@ fn parsing_benchmark(c: &mut Criterion) { } } -criterion_group!(benches, parsing_benchmark); +fn parsing_nested(c: &mut Criterion) { + let mut parsing = c.benchmark_group("Parsing"); + + 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(|| nomo::parser::parse(input.clone()).unwrap()); + }); + } +} + +criterion_group!(benches, parsing_benchmark, parsing_nested); criterion_main!(benches); diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 2b28a53..ee307ed 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -116,7 +116,6 @@ version = "0.1.0" dependencies = [ "annotate-snippets", "displaydoc", - "serde", "serde_json", "thiserror", "winnow", @@ -161,7 +160,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ "serde_core", - "serde_derive", ] [[package]]