nomo/benches/asting.rs
Marcel Müller d41cd57847 Add asting benchmark
Signed-off-by: Marcel Müller <neikos@neikos.email>
2026-03-13 07:40:21 +01:00

54 lines
1.7 KiB
Rust

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);