mirror of https://github.com/boa-dev/boa.git
Iban Eguia
5 years ago
committed by
GitHub
8 changed files with 199 additions and 133 deletions
@ -1,23 +1,72 @@
|
||||
#[macro_use] |
||||
extern crate criterion; |
||||
//! Benchmarks of the whole execution engine in Boa.
|
||||
|
||||
use boa::exec; |
||||
use boa::realm::Realm; |
||||
use criterion::{black_box, Criterion}; |
||||
use boa::{exec, realm::Realm}; |
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
||||
|
||||
static SRC: &str = r#" |
||||
static SYMBOL_CREATION: &str = r#" |
||||
let a = Symbol(); |
||||
let b = Symbol(); |
||||
let c = Symbol(); |
||||
"#; |
||||
|
||||
fn create_realm(c: &mut Criterion) { |
||||
c.bench_function("Create Realm", move |b| b.iter(Realm::create)); |
||||
} |
||||
|
||||
fn symbol_creation(c: &mut Criterion) { |
||||
c.bench_function("Symbol Creation", move |b| b.iter(|| exec(black_box(SRC)))); |
||||
c.bench_function("Symbol creation (Execution)", move |b| { |
||||
b.iter(|| exec(black_box(SYMBOL_CREATION))) |
||||
}); |
||||
} |
||||
|
||||
fn create_realm(c: &mut Criterion) { |
||||
c.bench_function("Create Realm", move |b| b.iter(|| Realm::create())); |
||||
static FOR_LOOP: &str = r#" |
||||
let a = 10; |
||||
let b = "hello"; |
||||
for (;;) { |
||||
a += 5; |
||||
|
||||
if a < 50 { |
||||
b += "world"; |
||||
} |
||||
|
||||
if (a > 100) { |
||||
break; |
||||
} |
||||
} |
||||
let c = a; |
||||
let d = b; |
||||
"#; |
||||
|
||||
fn for_loop_execution(c: &mut Criterion) { |
||||
c.bench_function("For loop (Execution)", move |b| { |
||||
b.iter(|| exec(black_box(FOR_LOOP))) |
||||
}); |
||||
} |
||||
|
||||
static FIBONACCI: &str = r#" |
||||
let num = 12; |
||||
|
||||
function fib(n) { |
||||
if (n <= 1) return 1; |
||||
return fib(n - 1) + fib(n - 2); |
||||
} |
||||
|
||||
let res = fib(num); |
||||
|
||||
res; |
||||
"#; |
||||
|
||||
fn fibonacci(c: &mut Criterion) { |
||||
c.bench_function("Fibonacci (Execution)", move |b| { |
||||
b.iter(|| exec(black_box(FIBONACCI))) |
||||
}); |
||||
} |
||||
|
||||
criterion_group!(benches, create_realm, symbol_creation); |
||||
criterion_main!(benches); |
||||
criterion_group!( |
||||
execution, |
||||
create_realm, |
||||
symbol_creation, |
||||
for_loop_execution, |
||||
fibonacci |
||||
); |
||||
criterion_main!(execution); |
||||
|
@ -1,28 +0,0 @@
|
||||
#[macro_use] |
||||
extern crate criterion; |
||||
|
||||
use boa::exec; |
||||
use criterion::black_box; |
||||
use criterion::Criterion; |
||||
|
||||
static SRC: &str = r#" |
||||
let num = 12; |
||||
|
||||
function fib(n) { |
||||
if (n <= 1) return 1; |
||||
return fib(n - 1) + fib(n - 2); |
||||
} |
||||
|
||||
let res = fib(num); |
||||
|
||||
res; |
||||
"#; |
||||
|
||||
fn fibonacci(c: &mut Criterion) { |
||||
c.bench_function("fibonacci (Execution)", move |b| { |
||||
b.iter(|| exec(black_box(SRC))) |
||||
}); |
||||
} |
||||
|
||||
criterion_group!(benches, fibonacci); |
||||
criterion_main!(benches); |
@ -0,0 +1,56 @@
|
||||
//! Benchmarks of the lexing process in Boa.
|
||||
|
||||
use boa::syntax::lexer::Lexer; |
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
||||
|
||||
static EXPRESSION: &str = r#" |
||||
1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; |
||||
"#; |
||||
|
||||
fn expression_lexer(c: &mut Criterion) { |
||||
c.bench_function("Expression (Lexer)", move |b| { |
||||
b.iter(|| { |
||||
let mut lexer = Lexer::new(black_box(EXPRESSION)); |
||||
|
||||
lexer.lex() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
static HELLO_WORLD: &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(HELLO_WORLD)); |
||||
// return the value into the blackbox so its not optimized away
|
||||
// https://gist.github.com/jasonwilliams/5325da61a794d8211dcab846d466c4fd
|
||||
lexer.lex() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
static FOR_LOOP: &str = r#" |
||||
for (let a = 10; a < 100; a++) { |
||||
if (a < 10) { |
||||
console.log("impossible D:"); |
||||
} else if (a < 50) { |
||||
console.log("starting"); |
||||
} else { |
||||
console.log("finishing"); |
||||
} |
||||
} |
||||
"#; |
||||
|
||||
fn for_loop_lexer(c: &mut Criterion) { |
||||
c.bench_function("For loop (Lexer)", move |b| { |
||||
b.iter(|| { |
||||
let mut lexer = Lexer::new(black_box(FOR_LOOP)); |
||||
|
||||
lexer.lex() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
criterion_group!(lexer, expression_lexer, hello_world_lexer, for_loop_lexer); |
||||
criterion_main!(lexer); |
@ -1,30 +1,69 @@
|
||||
#[macro_use] |
||||
extern crate criterion; |
||||
//! Benchmarks of the parsing process in Boa.
|
||||
|
||||
use boa::syntax::lexer::Lexer; |
||||
use boa::syntax::parser::Parser; |
||||
use criterion::black_box; |
||||
use criterion::Criterion; |
||||
use boa::syntax::{lexer::Lexer, parser::Parser}; |
||||
use criterion::{black_box, criterion_group, criterion_main, 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], |
||||
); |
||||
// We include the lexing in the benchmarks, since they will get together soon, anyways.
|
||||
|
||||
c.bench_function("Expression (Parser)", move |b| { |
||||
b.iter(|| { |
||||
let mut lexer = Lexer::new(black_box(EXPRESSION)); |
||||
lexer.lex().expect("failed to lex"); |
||||
|
||||
Parser::new(&black_box(lexer.tokens)).parse_all() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
static HELLO_WORLD: &str = "let foo = 'hello world!'; foo;"; |
||||
|
||||
fn hello_world_parser(c: &mut Criterion) { |
||||
// We include the lexing in the benchmarks, since they will get together soon, anyways.
|
||||
|
||||
c.bench_function("Hello World (Parser)", move |b| { |
||||
b.iter(|| { |
||||
let mut lexer = Lexer::new(black_box(HELLO_WORLD)); |
||||
lexer.lex().expect("failed to lex"); |
||||
|
||||
Parser::new(&black_box(lexer.tokens)).parse_all() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
static FOR_LOOP: &str = r#" |
||||
for (let a = 10; a < 100; a++) { |
||||
if (a < 10) { |
||||
console.log("impossible D:"); |
||||
} else if (a < 50) { |
||||
console.log("starting"); |
||||
} else { |
||||
console.log("finishing"); |
||||
} |
||||
} |
||||
"#; |
||||
|
||||
fn for_loop_parser(c: &mut Criterion) { |
||||
// We include the lexing in the benchmarks, since they will get together soon, anyways.
|
||||
|
||||
c.bench_function("For loop (Parser)", move |b| { |
||||
b.iter(|| { |
||||
let mut lexer = Lexer::new(black_box(FOR_LOOP)); |
||||
lexer.lex().expect("failed to lex"); |
||||
|
||||
Parser::new(&black_box(lexer.tokens)).parse_all() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
criterion_group!(benches, expression_parser); |
||||
criterion_main!(benches); |
||||
criterion_group!( |
||||
parser, |
||||
expression_parser, |
||||
hello_world_parser, |
||||
for_loop_parser |
||||
); |
||||
criterion_main!(parser); |
||||
|
@ -1,46 +0,0 @@
|
||||
#[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)); |
||||
// return the value into the blackbox so its not optimized away
|
||||
// https://gist.github.com/jasonwilliams/5325da61a794d8211dcab846d466c4fd
|
||||
lexer.lex() |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
fn hello_world_parser(c: &mut Criterion) { |
||||
// Don't include lexing as part of the parser benchmark
|
||||
let mut lexer = Lexer::new(SRC); |
||||
lexer.lex().expect("failed to lex"); |
||||
let tokens = lexer.tokens; |
||||
c.bench_function_over_inputs( |
||||
"Hello World (Parser)", |
||||
move |b, tok| { |
||||
b.iter(|| { |
||||
Parser::new(&black_box(tok.to_vec())).parse_all().unwrap(); |
||||
}) |
||||
}, |
||||
vec![tokens], |
||||
); |
||||
} |
||||
|
||||
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); |
Loading…
Reference in new issue