summaryrefslogtreecommitdiff
path: root/autochomp/benches
diff options
context:
space:
mode:
Diffstat (limited to 'autochomp/benches')
-rw-r--r--autochomp/benches/parse.rs173
-rw-r--r--autochomp/benches/parse/data/12.nb1
-rw-r--r--autochomp/benches/parse/data/1548.nb40
-rw-r--r--autochomp/benches/parse/data/194.nb7
-rw-r--r--autochomp/benches/parse/data/24.nb1
-rw-r--r--autochomp/benches/parse/data/3096.nb82
-rw-r--r--autochomp/benches/parse/data/387.nb13
-rw-r--r--autochomp/benches/parse/data/48.nb2
-rw-r--r--autochomp/benches/parse/data/774.nb21
-rw-r--r--autochomp/benches/parse/data/97.nb3
-rw-r--r--autochomp/benches/parse/main.rs64
11 files changed, 234 insertions, 173 deletions
diff --git a/autochomp/benches/parse.rs b/autochomp/benches/parse.rs
deleted file mode 100644
index a42543a..0000000
--- a/autochomp/benches/parse.rs
+++ /dev/null
@@ -1,173 +0,0 @@
-use std::error::Error;
-
-use chewed::{IterWrapper, Parser};
-use chomp::{
- chomp::ast::{Function, NamedExpression},
- nibble,
-};
-use criterion::{
- criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration,
- Throughput,
-};
-
-const INPUTS: &[&str] = &[
- r##"match _ : None | "a" : Some;"##,
- r##"let opt(x) = _ : None | "a" : Some;
- match [plus](("a" : First) . (opt(plus) : Next));"##,
- r##"let opt(x) = _ : None | x : Some;
- let plus(x) = [plus]((x : First) . (opt(plus) : Next));
- let star(x) = opt(plus(x));
- match [rec]("a" : Base | "b" . rec : Step);"##,
- r##"let opt(x) = _ : None | x : Some;
- let plus(x) = [plus]((x : First) . (opt(plus) : Next));
- let star(x) = opt(plus(x));
- let star_(base, step) = [rec](base : Base | step . rec : Step);
- let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
- let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
- let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
- match "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";"##,
- r##"let opt(x) = _ : None | x : Some;
- let plus(x) = [plus]((x : First) . (opt(plus) : Next));
- let star(x) = opt(plus(x));
- let star_(base, step) = [rec](base : Base | step . rec : Step);
- let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
- let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
- let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
- let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
- "a" | "b" | "c" | "d" | "e" | "f" |
- "A" | "B" | "C" | "D" | "E" | "F" ;
- let XID_Start =
- "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
- "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
- "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
- "y" | "z" ;
- match "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" ;"##,
- r##"let opt(x) = _ : None | x : Some;
- let plus(x) = [plus]((x : First) . (opt(plus) : Next));
- let star(x) = opt(plus(x));
- let star_(base, step) = [rec](base : Base | step . rec : Step);
- let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
- let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
- let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
- let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
- "a" | "b" | "c" | "d" | "e" | "f" |
- "A" | "B" | "C" | "D" | "E" | "F" ;
- let XID_Start =
- "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
- "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
- "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
- "y" | "z" |
- "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
- "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
- "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
- "Y" | "Z" ;
- let XID_Continue =
- XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
- let literal_char =
- (" " | "!" | "#" | "$" | "%" | "&" | "'" |
- "(" | ")" | "*" | "+" | "," | "-" | "." | "/" |
- "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
- "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" |
- "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" |
- "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" |
- "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" |
- "X" | "Y" | "Z" | "[" | "]" | "^" | "_" |
- "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" );
- match "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" ;"##,
- r##"let opt(x) = _ : None | x : Some;
- let plus(x) = [plus]((x : First) . (opt(plus) : Next));
- let star(x) = opt(plus(x));
- let star_(base, step) = [rec](base : Base | step . rec : Step);
- let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
- let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
- let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
- let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
- "a" | "b" | "c" | "d" | "e" | "f" |
- "A" | "B" | "C" | "D" | "E" | "F" ;
- let XID_Start =
- "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
- "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
- "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
- "y" | "z" |
- "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
- "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
- "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
- "Y" | "Z" ;
- let XID_Continue =
- XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
- let literal_char =
- (" " | "!" | "#" | "$" | "%" | "&" | "'" |
- "(" | ")" | "*" | "+" | "," | "-" | "." | "/" |
- "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
- "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" |
- "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" |
- "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" |
- "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" |
- "X" | "Y" | "Z" | "[" | "]" | "^" | "_" |
- "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" |
- "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" |
- "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" |
- "x" | "y" | "z" | "{" | "|" | "}" | "~") : Literal |
- "\\" . (
- ("\"" | "'" | "n" | "r" | "t" | "\\" | "0") : Ascii |
- "x" . oct_digit . hex_digit : Oct |
- "u{" .hex_digit
- .opt(hex_digit
- .opt(hex_digit
- .opt(hex_digit
- .opt(hex_digit . opt(hex_digit))))) . "}" : Unicode
- ) : Escape ;
- let ws = plus(Pattern_Whitespace);
- let punctuated(x, p) = [rec]((x : First) . (opt(p . opt(ws) . rec) : Next));
- let list(x) = "(" . opt(ws) . [rec]((x : First) . (opt("," . opt(ws) . opt(rec)) : Next)) . ")";
- let epsilon = "_";
- let ident = XID_Start . star(XID_Continue);
- let literal = "\"" . (plus(literal_char) : Contents) . "\"";
- let parens(expr) = "(" . opt(ws) . (expr : Inner) . ")";
- let fix(expr) = "[" . opt(ws) . (ident : Arg) . opt(ws) . "]" . opt(ws) . (parens(expr) : Inner);
- let term(expr) =
- epsilon . opt(ws) : Epsilon
- | literal . opt(ws) : Literal
- | parens(expr) . opt(ws) : Parens
- | fix(expr) . opt(ws) : Fix
- | ident . opt(ws) . opt(list(expr) . opt(ws)) : CallOrVariable
- ;
- let label = ":" . opt(ws) . (ident : Label) . opt(ws);
- let cat(expr) = punctuated(term(expr), ".");
- let alt(expr) = punctuated((cat(expr) : Cat) . (opt(label) : Name), "|");
- let expr = [expr](alt(expr));
- let let = "let" . ws . (ident : Name) . opt(ws) . (opt(list(ident . opt(ws)) . opt(ws)) : Args) . "=" . opt(ws) . (expr : Expr) . ";" . opt(ws);
- let goal = "match" . ws . (expr : Expr) . ";" . opt(ws);
- match star_(star_(goal : Goal, let : Let), Pattern_Whitespace);"##,
-];
-
-fn parse_autochomp(input: &str) -> Result<(Vec<Function>, NamedExpression), Box<dyn Error>> {
- IterWrapper::new(input.chars())
- .parse::<autochomp::Ast>()
- .map_err(|e| Box::new(e) as Box<dyn Error>)
- .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box<dyn Error>))
-}
-
-fn parse_chomp(input: &str) -> Result<(Vec<Function>, NamedExpression), Box<dyn Error>> {
- syn::parse_str::<nibble::File>(input)
- .map_err(|e| Box::new(e) as Box<dyn Error>)
- .and_then(|file| file.convert().map_err(|e| Box::new(e) as Box<dyn Error>))
-}
-
-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);
diff --git a/autochomp/benches/parse/data/12.nb b/autochomp/benches/parse/data/12.nb
new file mode 100644
index 0000000..eaa4670
--- /dev/null
+++ b/autochomp/benches/parse/data/12.nb
@@ -0,0 +1 @@
+match "ab";
diff --git a/autochomp/benches/parse/data/1548.nb b/autochomp/benches/parse/data/1548.nb
new file mode 100644
index 0000000..cabdfe9
--- /dev/null
+++ b/autochomp/benches/parse/data/1548.nb
@@ -0,0 +1,40 @@
+let bot = !(/rec/ "a" . rec);
+let zero = /zero suc/ zero;
+let suc n = /zero suc/ suc (n zero suc);
+
+let opt some = _ : None | some;
+let plus iter = !(/plus/ iter . (opt plus));
+let star iter = opt (plus iter);
+
+let up_to x n = n bot (/rec/ x . opt rec);
+
+let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
+
+let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
+let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
+let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
+ "a" | "b" | "c" | "d" | "e" | "f" |
+ "A" | "B" | "C" | "D" | "E" | "F" ;
+
+let XID_Start =
+ "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
+ "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
+ "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
+ "y" | "z" |
+ "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
+ "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
+ "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
+ "Y" | "Z" ;
+let XID_Continue =
+ XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
+
+match
+ (" " | "!" | "#" | "$" | "%" | "&" | "'" |
+ "(" | ")" | "*" | "+" | "," | "-" | "." | "/" |
+ "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
+ "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" |
+ "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" |
+ "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" |
+ "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" |
+ "X"|"Y"
+ );
diff --git a/autochomp/benches/parse/data/194.nb b/autochomp/benches/parse/data/194.nb
new file mode 100644
index 0000000..01730c6
--- /dev/null
+++ b/autochomp/benches/parse/data/194.nb
@@ -0,0 +1,7 @@
+let bot = !(/rec/ "a" . rec);
+let zero = /zero suc/ zero;
+let suc n = /zero suc/ suc (n zero suc);
+
+let opt some = _ : None | some;
+let plus iter = !(/plus/ iter . (opt plus));
+match opt "ab";
diff --git a/autochomp/benches/parse/data/24.nb b/autochomp/benches/parse/data/24.nb
new file mode 100644
index 0000000..f960c3b
--- /dev/null
+++ b/autochomp/benches/parse/data/24.nb
@@ -0,0 +1 @@
+match !(/rec/ "a".rec);
diff --git a/autochomp/benches/parse/data/3096.nb b/autochomp/benches/parse/data/3096.nb
new file mode 100644
index 0000000..f90100c
--- /dev/null
+++ b/autochomp/benches/parse/data/3096.nb
@@ -0,0 +1,82 @@
+let bot = !(/rec/ "a" . rec);
+let zero = /zero suc/ zero;
+let suc n = /zero suc/ suc (n zero suc);
+
+let opt some = _ : None | some;
+let plus iter = !(/plus/ iter . (opt plus));
+let star iter = opt (plus iter);
+
+let up_to x n = n bot (/rec/ x . opt rec);
+
+let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
+
+let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
+let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
+let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
+ "a" | "b" | "c" | "d" | "e" | "f" |
+ "A" | "B" | "C" | "D" | "E" | "F" ;
+
+let XID_Start =
+ "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
+ "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
+ "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
+ "y" | "z" |
+ "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
+ "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
+ "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
+ "Y" | "Z" ;
+let XID_Continue =
+ XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
+
+let literal_char =
+ (" " | "!" | "#" | "$" | "%" | "&" | "'" |
+ "(" | ")" | "*" | "+" | "," | "-" | "." | "/" |
+ "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
+ "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" |
+ "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" |
+ "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" |
+ "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" |
+ "X" | "Y" | "Z" | "[" | "]" | "^" | "_" |
+ "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" |
+ "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" |
+ "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" |
+ "x" | "y" | "z" | "{" | "|" | "}" | "~") : Literal |
+ "\\" . (
+ ("\"" | "'" | "n" | "r" | "t" | "\\" | "0") : Ascii |
+ "x" . oct_digit . hex_digit : Oct |
+ "u{" . up_to hex_digit (suc (suc (suc (suc (suc (suc zero)))))) . "}" : Unicode
+ ) : Escape ;
+
+let ws = plus Pattern_Whitespace;
+let ows = opt ws;
+
+let list inner = !(/list/ inner . opt (ws . opt list));
+let separated inner sep = !(/separated/ inner . opt (sep . ows . separated));
+
+let epsilon = "_";
+let ident = XID_Start . star XID_Continue;
+let literal = "\"" . (plus literal_char : Contents) . "\"";
+let fix term = "!" . ows . term;
+let parens expr = "(" . ows . expr . ")";
+
+let names = list ident;
+
+let term expr = !(/term/
+ epsilon : Epsilon
+ | literal : Literal
+ | parens expr : Parens
+ | fix term : Fix
+ | ident : Variable
+ );
+
+let label = ":" . ows . ident . ows;
+
+let call expr = list (term expr);
+let cat expr = separated (call expr) ".";
+let alt expr = separated (cat expr . opt label : Labelled) "|";
+let lambda expr = "/" . ows . names . "/" . ows . alt expr;
+let expr = !(/expr/ alt expr | lambda expr);
+let goal = "match" . ws . expr . ";" . ows;
+let let stmt = "let" . ws . names . "=" . ows . expr . ";" . ows . stmt;
+let stmt = !(/stmt/ let stmt | goal);
+match !(/skip/ Pattern_Whitespace . skip | stmt);
diff --git a/autochomp/benches/parse/data/387.nb b/autochomp/benches/parse/data/387.nb
new file mode 100644
index 0000000..0f60b89
--- /dev/null
+++ b/autochomp/benches/parse/data/387.nb
@@ -0,0 +1,13 @@
+let bot = !(/rec/ "a" . rec);
+let zero = /zero suc/ zero;
+let suc n = /zero suc/ suc (n zero suc);
+
+let opt some = _ : None | some;
+let plus iter = !(/plus/ iter . (opt plus));
+let star iter = opt (plus iter);
+
+let up_to x n = n bot (/rec/ x . opt rec);
+
+let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
+
+match = "0" |"1";
diff --git a/autochomp/benches/parse/data/48.nb b/autochomp/benches/parse/data/48.nb
new file mode 100644
index 0000000..7059bb8
--- /dev/null
+++ b/autochomp/benches/parse/data/48.nb
@@ -0,0 +1,2 @@
+let bot = !(/rec/ "a" . rec);
+match /zero/zero;
diff --git a/autochomp/benches/parse/data/774.nb b/autochomp/benches/parse/data/774.nb
new file mode 100644
index 0000000..89c22ca
--- /dev/null
+++ b/autochomp/benches/parse/data/774.nb
@@ -0,0 +1,21 @@
+let bot = !(/rec/ "a" . rec);
+let zero = /zero suc/ zero;
+let suc n = /zero suc/ suc (n zero suc);
+
+let opt some = _ : None | some;
+let plus iter = !(/plus/ iter . (opt plus));
+let star iter = opt (plus iter);
+
+let up_to x n = n bot (/rec/ x . opt rec);
+
+let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}";
+
+let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ;
+let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
+let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
+ "a" | "b" | "c" | "d" | "e" | "f" |
+ "A" | "B" | "C" | "D" | "E" | "F" ;
+
+match
+ "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
+ "i" | "j" | "k" | "l";
diff --git a/autochomp/benches/parse/data/97.nb b/autochomp/benches/parse/data/97.nb
new file mode 100644
index 0000000..d0d00f9
--- /dev/null
+++ b/autochomp/benches/parse/data/97.nb
@@ -0,0 +1,3 @@
+let bot = !(/rec/ ("a" . rec));
+let zero = /zero suc/ zero;
+match (/zero suc/ suc (_ zero suc));
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<NamedExpression, Box<dyn Error>> {
+ IterWrapper::new(input.chars())
+ .parse::<autochomp::Ast>()
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ .and_then(|ast| {
+ ast.convert(&mut Context::default())
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ })
+}
+
+fn parse_chomp(input: &str) -> Result<NamedExpression, Box<dyn Error>> {
+ syn::parse_str::<nibble::Statement>(input)
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ .and_then(|stmt| {
+ stmt.convert(&mut Context::default())
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ })
+}
+
+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);