diff --git a/Cargo.toml b/Cargo.toml index 3d0bd41e4d..1946c3919e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,10 @@ harness = false name = "exec" harness = false +[[bench]] +name = "parser" +harness = false + [[bin]] name = "boa" path = "src/bin/bin.rs" diff --git a/benches/parser.rs b/benches/parser.rs new file mode 100644 index 0000000000..f201c71258 --- /dev/null +++ b/benches/parser.rs @@ -0,0 +1,30 @@ +#[macro_use] +extern crate criterion; + +use boa::syntax::lexer::Lexer; +use boa::syntax::parser::Parser; +use criterion::black_box; +use criterion::Criterion; + +static EXPRESSION: &str = r#" +1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; +"#; + +fn expression_parser(c: &mut Criterion) { + // Don't include lexing as part of the parser benchmark + let mut lexer = Lexer::new(EXPRESSION); + lexer.lex().expect("failed to lex"); + let tokens = lexer.tokens; + c.bench_function_over_inputs( + "Expression (Parser)", + move |b, tok| { + b.iter(|| { + Parser::new(black_box(tok.to_vec())).parse_all().unwrap(); + }) + }, + vec![tokens], + ); +} + +criterion_group!(benches, expression_parser); +criterion_main!(benches);