Rust编写的JavaScript引擎,该项目是一个试验性质的项目。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
1.0 KiB

#[macro_use]
extern crate criterion;
use boa::exec;
use boa::syntax::lexer::Lexer;
use boa::syntax::parser::Parser;
use criterion::black_box;
use criterion::Criterion;
static SRC: &str = "let foo = 'hello world!'; foo;";
fn hello_world_lexer(c: &mut Criterion) {
c.bench_function("Hello World (Lexer)", move |b| {
b.iter(|| {
let mut lexer = Lexer::new(black_box(SRC));
let _ = lexer.lex();
})
});
}
fn hello_world_parser(c: &mut Criterion) {
c.bench_function("Hello World (Parser)", move |b| {
b.iter(|| {
let mut lexer = Lexer::new(SRC);
lexer.lex().unwrap();
let tokens = lexer.tokens;
Parser::new(black_box(tokens)).parse_all().unwrap();
})
});
}
fn hello_world(c: &mut Criterion) {
c.bench_function("Hello World (Execution)", move |b| {
b.iter(|| exec(black_box(SRC)))
});
}
criterion_group!(benches, hello_world, hello_world_lexer, hello_world_parser);
criterion_main!(benches);