-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add parser benchmark for expressions (#226)
- Loading branch information
1 parent
f134a07
commit 27bd553
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |