Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more benchmarks #323

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ default = ["wasm-bindgen"]
[dependencies]
gc = "0.3.3"
gc_derive = "0.3.2"
serde_json = "1.0.48"
serde_json = "1.0.51"
rand = "0.7.3"
regex = "1.3.6"

# Optional Dependencies
wasm-bindgen = { version = "0.2.59", optional = true }
serde = { version = "1.0.105", features = ["derive"], optional = true }
wasm-bindgen = { version = "0.2.60", optional = true }
serde = { version = "1.0.106", features = ["derive"], optional = true }

[dev-dependencies]
criterion = "0.3.1"
Expand All @@ -34,17 +34,13 @@ name = "boa"
bench = false

[[bench]]
name = "string"
name = "lexer"
harness = false

[[bench]]
name = "fib"
name = "parser"
harness = false

[[bench]]
name = "exec"
harness = false

[[bench]]
name = "parser"
harness = false
harness = false
71 changes: 60 additions & 11 deletions boa/benches/exec.rs
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);
28 changes: 0 additions & 28 deletions boa/benches/fib.rs

This file was deleted.

56 changes: 56 additions & 0 deletions boa/benches/lexer.rs
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);