Skip to content

Commit

Permalink
add parser benchmark for expressions (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams authored Jan 18, 2020
1 parent f134a07 commit 27bd553
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ harness = false
name = "exec"
harness = false

[[bench]]
name = "parser"
harness = false

[[bin]]
name = "boa"
path = "src/bin/bin.rs"
Expand Down
30 changes: 30 additions & 0 deletions benches/parser.rs
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 27bd553

Please sign in to comment.