From dfc08ff2c6580bbeb3951b223e0332546ba3b0d9 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Thu, 6 May 2021 19:40:59 +0100 Subject: Introduce lambda expressions. --- autochomp/benches/parse/main.rs | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 autochomp/benches/parse/main.rs (limited to 'autochomp/benches/parse/main.rs') diff --git a/autochomp/benches/parse/main.rs b/autochomp/benches/parse/main.rs new file mode 100644 index 0000000..64fd88a --- /dev/null +++ b/autochomp/benches/parse/main.rs @@ -0,0 +1,64 @@ +use std::error::Error; + +use chewed::{IterWrapper, Parser}; +use chomp::{ + chomp::ast::NamedExpression, + nibble::{ + self, + convert::{Context, Convert}, + }, +}; +use criterion::{ + criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, + Throughput, +}; + +const INPUTS: &[&str] = &[ + include_str!("data/12.nb"), + include_str!("data/24.nb"), + include_str!("data/48.nb"), + include_str!("data/97.nb"), + include_str!("data/194.nb"), + include_str!("data/387.nb"), + include_str!("data/774.nb"), + include_str!("data/1548.nb"), + include_str!("data/3096.nb"), + +]; + +fn parse_autochomp(input: &str) -> Result> { + IterWrapper::new(input.chars()) + .parse::() + .map_err(|e| Box::new(e) as Box) + .and_then(|ast| { + ast.convert(&mut Context::default()) + .map_err(|e| Box::new(e) as Box) + }) +} + +fn parse_chomp(input: &str) -> Result> { + syn::parse_str::(input) + .map_err(|e| Box::new(e) as Box) + .and_then(|stmt| { + stmt.convert(&mut Context::default()) + .map_err(|e| Box::new(e) as Box) + }) +} + +fn bench_parse(c: &mut Criterion) { + let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); + let mut group = c.benchmark_group("Parse"); + group.plot_config(plot_config); + for (i, input) in INPUTS.iter().enumerate() { + group.throughput(Throughput::Bytes(input.len() as u64)); + group.bench_with_input(BenchmarkId::new("Chomp", i), *input, |b, i| { + b.iter(|| parse_chomp(i)) + }); + group.bench_with_input(BenchmarkId::new("AutoChomp", i), *input, |b, i| { + b.iter(|| parse_autochomp(i)) + }); + } +} + +criterion_group!(benches, bench_parse); +criterion_main!(benches); -- cgit v1.2.3