Browse Source

Added more benchmarks (#323)

pull/327/head
Iban Eguia 5 years ago committed by GitHub
parent
commit
cb589cd8b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      Cargo.lock
  2. 14
      boa/Cargo.toml
  3. 71
      boa/benches/exec.rs
  4. 28
      boa/benches/fib.rs
  5. 56
      boa/benches/lexer.rs
  6. 75
      boa/benches/parser.rs
  7. 46
      boa/benches/string.rs
  8. 2
      boa_cli/Cargo.toml

32
Cargo.lock generated

@ -2,7 +2,7 @@
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "Boa" name = "Boa"
version = "0.6.0" version = "0.7.0"
dependencies = [ dependencies = [
"criterion", "criterion",
"gc", "gc",
@ -57,7 +57,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]] [[package]]
name = "boa_cli" name = "boa_cli"
version = "0.6.0" version = "0.7.0"
dependencies = [ dependencies = [
"Boa", "Boa",
"structopt", "structopt",
@ -384,9 +384,9 @@ checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "0.4.12" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7" checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
dependencies = [ dependencies = [
"proc-macro-error-attr", "proc-macro-error-attr",
"proc-macro2", "proc-macro2",
@ -397,9 +397,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro-error-attr" name = "proc-macro-error-attr"
version = "0.4.12" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de" checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.3", "quote 1.0.3",
@ -571,18 +571,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.105" version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff" checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.105" version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8" checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote 1.0.3", "quote 1.0.3",
@ -591,9 +591,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.48" version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" checksum = "da07b57ee2623368351e9a0488bb0b261322a15a6e0ae53e243cbdc0f4208da9"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -608,9 +608,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]] [[package]]
name = "structopt" name = "structopt"
version = "0.3.12" version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8faa2719539bbe9d77869bfb15d4ee769f99525e707931452c97b693b3f159d" checksum = "ff6da2e8d107dfd7b74df5ef4d205c6aebee0706c647f6bc6a2d5789905c00fb"
dependencies = [ dependencies = [
"clap", "clap",
"lazy_static", "lazy_static",
@ -619,9 +619,9 @@ dependencies = [
[[package]] [[package]]
name = "structopt-derive" name = "structopt-derive"
version = "0.4.5" version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f88b8e18c69496aad6f9ddf4630dd7d585bcaf765786cb415b9aec2fe5a0430" checksum = "a489c87c08fbaf12e386665109dd13470dcc9c4583ea3e10dd2b4523e5ebd9ac"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-error", "proc-macro-error",

14
boa/Cargo.toml

@ -17,13 +17,13 @@ default = ["wasm-bindgen"]
[dependencies] [dependencies]
gc = "0.3.3" gc = "0.3.3"
gc_derive = "0.3.2" gc_derive = "0.3.2"
serde_json = "1.0.48" serde_json = "1.0.51"
rand = "0.7.3" rand = "0.7.3"
regex = "1.3.6" regex = "1.3.6"
# Optional Dependencies # Optional Dependencies
wasm-bindgen = { version = "0.2.59", optional = true } wasm-bindgen = { version = "0.2.60", optional = true }
serde = { version = "1.0.105", features = ["derive"], optional = true } serde = { version = "1.0.106", features = ["derive"], optional = true }
[dev-dependencies] [dev-dependencies]
criterion = "0.3.1" criterion = "0.3.1"
@ -34,17 +34,13 @@ name = "boa"
bench = false bench = false
[[bench]] [[bench]]
name = "string" name = "lexer"
harness = false harness = false
[[bench]] [[bench]]
name = "fib" name = "parser"
harness = false harness = false
[[bench]] [[bench]]
name = "exec" name = "exec"
harness = false harness = false
[[bench]]
name = "parser"
harness = false

71
boa/benches/exec.rs

@ -1,23 +1,72 @@
#[macro_use] //! Benchmarks of the whole execution engine in Boa.
extern crate criterion;
use boa::exec; use boa::{exec, realm::Realm};
use boa::realm::Realm; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{black_box, Criterion};
static SRC: &str = r#" static SYMBOL_CREATION: &str = r#"
let a = Symbol(); let a = Symbol();
let b = Symbol(); let b = Symbol();
let c = 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) { 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) { static FOR_LOOP: &str = r#"
c.bench_function("Create Realm", move |b| b.iter(|| Realm::create())); 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_group!(
criterion_main!(benches); execution,
create_realm,
symbol_creation,
for_loop_execution,
fibonacci
);
criterion_main!(execution);

28
boa/benches/fib.rs

@ -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);

56
boa/benches/lexer.rs

@ -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);

75
boa/benches/parser.rs

@ -1,30 +1,69 @@
#[macro_use] //! Benchmarks of the parsing process in Boa.
extern crate criterion;
use boa::syntax::lexer::Lexer; use boa::syntax::{lexer::Lexer, parser::Parser};
use boa::syntax::parser::Parser; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::black_box;
use criterion::Criterion;
static EXPRESSION: &str = r#" static EXPRESSION: &str = r#"
1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; 1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1;
"#; "#;
fn expression_parser(c: &mut Criterion) { fn expression_parser(c: &mut Criterion) {
// Don't include lexing as part of the parser benchmark // We include the lexing in the benchmarks, since they will get together soon, anyways.
let mut lexer = Lexer::new(EXPRESSION);
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"); lexer.lex().expect("failed to lex");
let tokens = lexer.tokens;
c.bench_function_over_inputs( Parser::new(&black_box(lexer.tokens)).parse_all()
"Expression (Parser)", })
move |b, tok| { });
}
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(|| { b.iter(|| {
Parser::new(&black_box(tok.to_vec())).parse_all().unwrap(); let mut lexer = Lexer::new(black_box(FOR_LOOP));
lexer.lex().expect("failed to lex");
Parser::new(&black_box(lexer.tokens)).parse_all()
}) })
}, });
vec![tokens],
);
} }
criterion_group!(benches, expression_parser); criterion_group!(
criterion_main!(benches); parser,
expression_parser,
hello_world_parser,
for_loop_parser
);
criterion_main!(parser);

46
boa/benches/string.rs

@ -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);

2
boa_cli/Cargo.toml

@ -12,4 +12,4 @@ edition = "2018"
[dependencies] [dependencies]
Boa = { path = "../boa", features = ["serde-ast"], default-features = false } Boa = { path = "../boa", features = ["serde-ast"], default-features = false }
structopt = "0.3.12" structopt = "0.3.13"

Loading…
Cancel
Save