Browse Source

add parser benchmark for expressions (#226)

pull/228/head
Jason Williams 5 years ago committed by GitHub
parent
commit
27bd553c59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Cargo.toml
  2. 30
      benches/parser.rs

4
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"

30
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);
Loading…
Cancel
Save