From d2939fffe324a4c3c90d40fab5df0c6d137f3f04 Mon Sep 17 00:00:00 2001 From: Iban Eguia Date: Sun, 14 Jun 2020 16:32:07 +0200 Subject: [PATCH] Added string benchmarks, and updated dependencies (#491) --- Cargo.lock | 25 ++++++++-------- boa/Cargo.toml | 10 +++---- boa/benches/exec.rs | 73 +++++++++++++++++++++++++++++++++++++++++++++ boa_cli/Cargo.toml | 2 +- 4 files changed, 92 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95f01ee1bd..e7335de7ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,12 +211,13 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab6bffe714b6bb07e42f201352c34f51fefd355ace793f9e638ebd52d23f98d2" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ "cfg-if", "crossbeam-utils", + "maybe-uninit", ] [[package]] @@ -307,9 +308,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91780f809e750b0a89f5544be56617ff6b1227ee485bcb06ebe10cdf89bd3b71" +checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" dependencies = [ "libc", ] @@ -434,9 +435,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +checksum = "b7f3fc75e3697059fb1bc465e3d8cca6cf92f56854f201158b3f9c77d5a3cfa0" dependencies = [ "autocfg", "num-integer", @@ -446,9 +447,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" dependencies = [ "autocfg", "num-traits", @@ -456,9 +457,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ "autocfg", ] @@ -481,9 +482,9 @@ checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" [[package]] name = "oorandom" -version = "11.1.1" +version = "11.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94af325bc33c7f60191be4e2c984d48aaa21e2854f473b85398344b60c9b6358" +checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c" [[package]] name = "parking_lot" diff --git a/boa/Cargo.toml b/boa/Cargo.toml index a392d143e0..b8b28f45d3 100644 --- a/boa/Cargo.toml +++ b/boa/Cargo.toml @@ -14,14 +14,14 @@ edition = "2018" profiler = ["measureme", "once_cell"] [dependencies] -gc = { version = "0.3.5", features = ["derive"] } -serde_json = "1.0.53" +gc = { version = "0.3.6", features = ["derive"] } +serde_json = "1.0.55" rand = "0.7.3" -num-traits = "0.2.11" +num-traits = "0.2.12" regex = "1.3.9" rustc-hash = "1.1.0" -num-bigint = { version = "0.2.6", features = ["serde"] } -num-integer = "0.1.42" +num-bigint = { version = "0.3.0", features = ["serde"] } +num-integer = "0.1.43" bitflags = "1.2.1" # Optional Dependencies diff --git a/boa/benches/exec.rs b/boa/benches/exec.rs index 7377bcdadb..11a1c2a8a1 100644 --- a/boa/benches/exec.rs +++ b/boa/benches/exec.rs @@ -381,6 +381,76 @@ fn array_pop(c: &mut Criterion) { }); } +static STRING_CONCAT: &str = r#" +(function(){ + var a = "hello"; + var b = "world"; + + var c = a + b; +})(); +"#; + +fn string_concat(c: &mut Criterion) { + let realm = Realm::create(); + let mut engine = Interpreter::new(realm); + + let mut lexer = Lexer::new(black_box(STRING_CONCAT)); + lexer.lex().expect("failed to lex"); + + let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap(); + + c.bench_function("String concatenation (Execution)", move |b| { + b.iter(|| black_box(&nodes).run(&mut engine).unwrap()) + }); +} + +static STRING_COMPARE: &str = r#" +(function(){ + var a = "hello"; + var b = "world"; + + var c = a == b; + + var d = b; + var e = d == b; +})(); +"#; + +fn string_compare(c: &mut Criterion) { + let realm = Realm::create(); + let mut engine = Interpreter::new(realm); + + let mut lexer = Lexer::new(black_box(STRING_COMPARE)); + lexer.lex().expect("failed to lex"); + + let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap(); + + c.bench_function("String comparison (Execution)", move |b| { + b.iter(|| black_box(&nodes).run(&mut engine).unwrap()) + }); +} + +static STRING_COPY: &str = r#" +(function(){ + var a = "hello"; + var b = a; +})(); +"#; + +fn string_copy(c: &mut Criterion) { + let realm = Realm::create(); + let mut engine = Interpreter::new(realm); + + let mut lexer = Lexer::new(black_box(STRING_COPY)); + lexer.lex().expect("failed to lex"); + + let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap(); + + c.bench_function("String copy (Execution)", move |b| { + b.iter(|| black_box(&nodes).run(&mut engine).unwrap()) + }); +} + criterion_group!( execution, create_realm, @@ -397,5 +467,8 @@ criterion_group!( regexp_creation, regexp_literal, regexp, + string_concat, + string_compare, + string_copy, ); criterion_main!(execution); diff --git a/boa_cli/Cargo.toml b/boa_cli/Cargo.toml index 89a745e33e..1fe486f901 100644 --- a/boa_cli/Cargo.toml +++ b/boa_cli/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] Boa = { path = "../boa", features = ["serde"] } structopt = "0.3.14" -serde_json = "1.0.53" +serde_json = "1.0.55" [target.x86_64-unknown-linux-gnu.dependencies] jemallocator = "0.3.2"