-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
199 additions
and
133 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -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); |
This file was deleted.
Oops, something went wrong.
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,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); |
Oops, something went wrong.