Add asting benchmark
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
9aeeb4eb5b
commit
d41cd57847
2 changed files with 58 additions and 0 deletions
54
benches/asting.rs
Normal file
54
benches/asting.rs
Normal file
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue