diff --git a/boa/benches/bench_scripts/arithmetic_operations.js b/boa/benches/bench_scripts/arithmetic_operations.js new file mode 100644 index 0000000000..48d85ae60d --- /dev/null +++ b/boa/benches/bench_scripts/arithmetic_operations.js @@ -0,0 +1 @@ +((2 + 2) ** 3 / 100 - 5 ** 3 * -1000) ** 2 + 100 - 8 diff --git a/boa/benches/bench_scripts/array_access.js b/boa/benches/bench_scripts/array_access.js new file mode 100644 index 0000000000..de2f7ea782 --- /dev/null +++ b/boa/benches/bench_scripts/array_access.js @@ -0,0 +1,7 @@ +(function () { + let testArr = [1,2,3,4,5]; + + let res = testArr[2]; + + return res; +})(); diff --git a/boa/benches/bench_scripts/array_create.js b/boa/benches/bench_scripts/array_create.js new file mode 100644 index 0000000000..85e010426c --- /dev/null +++ b/boa/benches/bench_scripts/array_create.js @@ -0,0 +1,8 @@ +(function(){ + let testArr = []; + for (let a = 0; a <= 500; a++) { + testArr[a] = ('p' + a); + } + + return testArr; +})(); diff --git a/boa/benches/bench_scripts/array_pop.js b/boa/benches/bench_scripts/array_pop.js new file mode 100644 index 0000000000..c1ea38d0dc --- /dev/null +++ b/boa/benches/bench_scripts/array_pop.js @@ -0,0 +1,24 @@ +(function(){ + let testArray = [83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, + 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, + 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, + 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, + 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, + 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, + 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, + 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, + 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, + 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, + 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, + 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, + 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, + 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, + 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, + 45, 93, 17, 28, 83, 62, 99, 36, 28]; + + while (testArray.length > 0) { + testArray.pop(); + } + + return testArray; +})(); diff --git a/boa/benches/bench_scripts/boolean_object_access.js b/boa/benches/bench_scripts/boolean_object_access.js new file mode 100644 index 0000000000..c8faaf56b0 --- /dev/null +++ b/boa/benches/bench_scripts/boolean_object_access.js @@ -0,0 +1,7 @@ +new Boolean( + !new Boolean( + new Boolean( + !(new Boolean(false).valueOf()) && (new Boolean(true).valueOf()) + ).valueOf() + ).valueOf() +).valueOf() diff --git a/boa/benches/bench_scripts/expression.js b/boa/benches/bench_scripts/expression.js new file mode 100644 index 0000000000..2c78c4eab7 --- /dev/null +++ b/boa/benches/bench_scripts/expression.js @@ -0,0 +1 @@ +1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; diff --git a/boa/benches/bench_scripts/fibonacci.js b/boa/benches/bench_scripts/fibonacci.js new file mode 100644 index 0000000000..408c45fd4d --- /dev/null +++ b/boa/benches/bench_scripts/fibonacci.js @@ -0,0 +1,10 @@ +(function () { + let num = 12; + + function fib(n) { + if (n <= 1) return 1; + return fib(n - 1) + fib(n - 2); + } + + return fib(num); +})(); diff --git a/boa/benches/bench_scripts/for_loop.js b/boa/benches/bench_scripts/for_loop.js new file mode 100644 index 0000000000..91860ca532 --- /dev/null +++ b/boa/benches/bench_scripts/for_loop.js @@ -0,0 +1,10 @@ +(function () { + let b = "hello"; + for (let a = 10; a < 100; a += 5) { + if (a < 50) { + b += "world"; + } + } + + return b; +})(); diff --git a/boa/benches/bench_scripts/goal_symbol_switch.js b/boa/benches/bench_scripts/goal_symbol_switch.js new file mode 100644 index 0000000000..a759c0978e --- /dev/null +++ b/boa/benches/bench_scripts/goal_symbol_switch.js @@ -0,0 +1,7 @@ +function foo(regex, num) {} + +let i = 0; +while (i < 1000000) { + foo(/ab+c/, 5.0/5); + i++; +} diff --git a/boa/benches/bench_scripts/hello_world.js b/boa/benches/bench_scripts/hello_world.js new file mode 100644 index 0000000000..7222e7a936 --- /dev/null +++ b/boa/benches/bench_scripts/hello_world.js @@ -0,0 +1 @@ +let foo = 'hello world!'; foo; diff --git a/boa/benches/bench_scripts/long_repetition.js b/boa/benches/bench_scripts/long_repetition.js new file mode 100644 index 0000000000..d8a2457312 --- /dev/null +++ b/boa/benches/bench_scripts/long_repetition.js @@ -0,0 +1,9 @@ +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"); + } +} diff --git a/boa/benches/bench_scripts/number_object_access.js b/boa/benches/bench_scripts/number_object_access.js new file mode 100644 index 0000000000..94dea9d317 --- /dev/null +++ b/boa/benches/bench_scripts/number_object_access.js @@ -0,0 +1,7 @@ +new Number( + new Number( + new Number( + new Number(100).valueOf() - 10.5 + ).valueOf() + 100 + ).valueOf() * 1.6 +) diff --git a/boa/benches/bench_scripts/object_creation.js b/boa/benches/bench_scripts/object_creation.js new file mode 100644 index 0000000000..1cb6add857 --- /dev/null +++ b/boa/benches/bench_scripts/object_creation.js @@ -0,0 +1,8 @@ +(function () { + let test = { + my_prop: "hello", + another: 65, + }; + + return test; +})(); diff --git a/boa/benches/bench_scripts/object_prop_access_const.js b/boa/benches/bench_scripts/object_prop_access_const.js new file mode 100644 index 0000000000..0f28a12b73 --- /dev/null +++ b/boa/benches/bench_scripts/object_prop_access_const.js @@ -0,0 +1,8 @@ +(function () { + let test = { + my_prop: "hello", + another: 65, + }; + + return test.my_prop; +})(); diff --git a/boa/benches/bench_scripts/object_prop_access_dyn.js b/boa/benches/bench_scripts/object_prop_access_dyn.js new file mode 100644 index 0000000000..21fa502526 --- /dev/null +++ b/boa/benches/bench_scripts/object_prop_access_dyn.js @@ -0,0 +1,8 @@ +(function () { + let test = { + my_prop: "hello", + another: 65, + }; + + return test["my" + "_prop"]; +})(); diff --git a/boa/benches/bench_scripts/regexp.js b/boa/benches/bench_scripts/regexp.js new file mode 100644 index 0000000000..8f580f8abb --- /dev/null +++ b/boa/benches/bench_scripts/regexp.js @@ -0,0 +1,5 @@ +(function () { + let regExp = new RegExp('hello', 'i'); + + return regExp.test("Hello World"); +})(); diff --git a/boa/benches/bench_scripts/regexp_creation.js b/boa/benches/bench_scripts/regexp_creation.js new file mode 100644 index 0000000000..99eb3456b9 --- /dev/null +++ b/boa/benches/bench_scripts/regexp_creation.js @@ -0,0 +1,5 @@ +(function () { + let regExp = new RegExp('hello', 'i'); + + return regExp; +})(); diff --git a/boa/benches/bench_scripts/regexp_literal.js b/boa/benches/bench_scripts/regexp_literal.js new file mode 100644 index 0000000000..462260db73 --- /dev/null +++ b/boa/benches/bench_scripts/regexp_literal.js @@ -0,0 +1,5 @@ +(function () { + let regExp = /hello/i; + + return regExp.test("Hello World"); +})(); diff --git a/boa/benches/bench_scripts/regexp_literal_creation.js b/boa/benches/bench_scripts/regexp_literal_creation.js new file mode 100644 index 0000000000..339df6c26d --- /dev/null +++ b/boa/benches/bench_scripts/regexp_literal_creation.js @@ -0,0 +1,5 @@ +(function () { + let regExp = /hello/i; + + return regExp; +})(); diff --git a/boa/benches/bench_scripts/string_compare.js b/boa/benches/bench_scripts/string_compare.js new file mode 100644 index 0000000000..1aa59db2ab --- /dev/null +++ b/boa/benches/bench_scripts/string_compare.js @@ -0,0 +1,9 @@ +(function(){ + var a = "hello"; + var b = "world"; + + var c = a == b; + + var d = b; + var e = d == b; +})(); diff --git a/boa/benches/bench_scripts/string_concat.js b/boa/benches/bench_scripts/string_concat.js new file mode 100644 index 0000000000..e93a0b7825 --- /dev/null +++ b/boa/benches/bench_scripts/string_concat.js @@ -0,0 +1,6 @@ +(function(){ + var a = "hello"; + var b = "world"; + + var c = a + b; +})(); diff --git a/boa/benches/bench_scripts/string_copy.js b/boa/benches/bench_scripts/string_copy.js new file mode 100644 index 0000000000..4a751f6fa6 --- /dev/null +++ b/boa/benches/bench_scripts/string_copy.js @@ -0,0 +1,4 @@ +(function(){ + var a = "hello"; + var b = a; +})(); diff --git a/boa/benches/bench_scripts/string_object_access.js b/boa/benches/bench_scripts/string_object_access.js new file mode 100644 index 0000000000..0cf001c1ae --- /dev/null +++ b/boa/benches/bench_scripts/string_object_access.js @@ -0,0 +1,7 @@ +new String( + new String( + new String( + new String('Hello').valueOf() + new String(", world").valueOf() + ).valueOf() + '!' + ).valueOf() +).valueOf() diff --git a/boa/benches/bench_scripts/symbol_creation.js b/boa/benches/bench_scripts/symbol_creation.js new file mode 100644 index 0000000000..f7b101563f --- /dev/null +++ b/boa/benches/bench_scripts/symbol_creation.js @@ -0,0 +1,3 @@ +(function () { + return Symbol(); +})(); diff --git a/boa/benches/exec.rs b/boa/benches/exec.rs index dffda1c019..4b53386466 100644 --- a/boa/benches/exec.rs +++ b/boa/benches/exec.rs @@ -10,16 +10,12 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; )] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -static SYMBOL_CREATION: &str = r#" -(function () { - return Symbol(); -})(); -"#; - fn create_realm(c: &mut Criterion) { c.bench_function("Create Realm", move |b| b.iter(Realm::create)); } +static SYMBOL_CREATION: &str = include_str!("bench_scripts/symbol_creation.js"); + fn symbol_creation(c: &mut Criterion) { // Create new Realm and interpreter. let realm = Realm::create(); @@ -38,18 +34,7 @@ fn symbol_creation(c: &mut Criterion) { }); } -static FOR_LOOP: &str = r#" -(function () { - let b = "hello"; - for (let a = 10; a < 100; a += 5) { - if (a < 50) { - b += "world"; - } - } - - return b; -})(); -"#; +static FOR_LOOP: &str = include_str!("bench_scripts/for_loop.js"); fn for_loop_execution(c: &mut Criterion) { // Create new Realm and interpreter. @@ -69,18 +54,7 @@ fn for_loop_execution(c: &mut Criterion) { }); } -static FIBONACCI: &str = r#" -(function () { - let num = 12; - - function fib(n) { - if (n <= 1) return 1; - return fib(n - 1) + fib(n - 2); - } - - return fib(num); -})(); -"#; +static FIBONACCI: &str = include_str!("bench_scripts/fibonacci.js"); fn fibonacci(c: &mut Criterion) { // Create new Realm and interpreter. @@ -100,16 +74,7 @@ fn fibonacci(c: &mut Criterion) { }); } -static OBJECT_CREATION: &str = r#" -(function () { - let test = { - my_prop: "hello", - another: 65, - }; - - return test; -})(); -"#; +static OBJECT_CREATION: &str = include_str!("bench_scripts/object_creation.js"); fn object_creation(c: &mut Criterion) { // Create new Realm and interpreter. @@ -129,16 +94,7 @@ fn object_creation(c: &mut Criterion) { }); } -static OBJECT_PROP_ACCESS_CONST: &str = r#" -(function () { - let test = { - my_prop: "hello", - another: 65, - }; - - return test.my_prop; -})(); -"#; +static OBJECT_PROP_ACCESS_CONST: &str = include_str!("bench_scripts/object_prop_access_const.js"); fn object_prop_access_const(c: &mut Criterion) { // Create new Realm and interpreter. @@ -158,16 +114,7 @@ fn object_prop_access_const(c: &mut Criterion) { }); } -static OBJECT_PROP_ACCESS_DYN: &str = r#" -(function () { - let test = { - my_prop: "hello", - another: 65, - }; - - return test["my" + "_prop"]; -})(); -"#; +static OBJECT_PROP_ACCESS_DYN: &str = include_str!("bench_scripts/object_prop_access_dyn.js"); fn object_prop_access_dyn(c: &mut Criterion) { // Create new Realm and interpreter. @@ -187,13 +134,7 @@ fn object_prop_access_dyn(c: &mut Criterion) { }); } -static REGEXP_LITERAL_CREATION: &str = r#" -(function () { - let regExp = /hello/i; - - return regExp; -})(); -"#; +static REGEXP_LITERAL_CREATION: &str = include_str!("bench_scripts/regexp_literal_creation.js"); fn regexp_literal_creation(c: &mut Criterion) { // Create new Realm and interpreter. @@ -213,13 +154,7 @@ fn regexp_literal_creation(c: &mut Criterion) { }); } -static REGEXP_CREATION: &str = r#" -(function () { - let regExp = new RegExp('hello', 'i'); - - return regExp; -})(); -"#; +static REGEXP_CREATION: &str = include_str!("bench_scripts/regexp_creation.js"); fn regexp_creation(c: &mut Criterion) { // Create new Realm and interpreter. @@ -239,13 +174,7 @@ fn regexp_creation(c: &mut Criterion) { }); } -static REGEXP_LITERAL: &str = r#" -(function () { - let regExp = /hello/i; - - return regExp.test("Hello World"); -})(); -"#; +static REGEXP_LITERAL: &str = include_str!("bench_scripts/regexp_literal.js"); fn regexp_literal(c: &mut Criterion) { // Create new Realm and interpreter. @@ -265,13 +194,7 @@ fn regexp_literal(c: &mut Criterion) { }); } -static REGEXP: &str = r#" -(function () { - let regExp = new RegExp('hello', 'i'); - - return regExp.test("Hello World"); -})(); -"#; +static REGEXP: &str = include_str!("bench_scripts/regexp.js"); fn regexp(c: &mut Criterion) { // Create new Realm and interpreter. @@ -291,15 +214,7 @@ fn regexp(c: &mut Criterion) { }); } -static ARRAY_ACCESS: &str = r#" -(function () { - let testArr = [1,2,3,4,5]; - - let res = testArr[2]; - - return res; -})(); -"#; +static ARRAY_ACCESS: &str = include_str!("bench_scripts/array_access.js"); fn array_access(c: &mut Criterion) { let realm = Realm::create(); @@ -315,16 +230,7 @@ fn array_access(c: &mut Criterion) { }); } -static ARRAY_CREATE: &str = r#" -(function(){ - let testArr = []; - for (let a = 0; a <= 500; a++) { - testArr[a] = ('p' + a); - } - - return testArr; -})(); -"#; +static ARRAY_CREATE: &str = include_str!("bench_scripts/array_create.js"); fn array_creation(c: &mut Criterion) { let realm = Realm::create(); @@ -340,32 +246,7 @@ fn array_creation(c: &mut Criterion) { }); } -static ARRAY_POP: &str = r#" -(function(){ - let testArray = [83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, - 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, - 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, - 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, - 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, - 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, - 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, - 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, - 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, - 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, - 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, - 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, - 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28]; - - while (testArray.length > 0) { - testArray.pop(); - } - - return testArray; -})(); -"#; +static ARRAY_POP: &str = include_str!("bench_scripts/array_pop.js"); fn array_pop(c: &mut Criterion) { let realm = Realm::create(); @@ -381,14 +262,7 @@ fn array_pop(c: &mut Criterion) { }); } -static STRING_CONCAT: &str = r#" -(function(){ - var a = "hello"; - var b = "world"; - - var c = a + b; -})(); -"#; +static STRING_CONCAT: &str = include_str!("bench_scripts/string_concat.js"); fn string_concat(c: &mut Criterion) { let realm = Realm::create(); @@ -404,17 +278,7 @@ fn string_concat(c: &mut Criterion) { }); } -static STRING_COMPARE: &str = r#" -(function(){ - var a = "hello"; - var b = "world"; - - var c = a == b; - - var d = b; - var e = d == b; -})(); -"#; +static STRING_COMPARE: &str = include_str!("bench_scripts/string_compare.js"); fn string_compare(c: &mut Criterion) { let realm = Realm::create(); @@ -430,12 +294,7 @@ fn string_compare(c: &mut Criterion) { }); } -static STRING_COPY: &str = r#" -(function(){ - var a = "hello"; - var b = a; -})(); -"#; +static STRING_COPY: &str = include_str!("bench_scripts/string_copy.js"); fn string_copy(c: &mut Criterion) { let realm = Realm::create(); @@ -451,15 +310,7 @@ fn string_copy(c: &mut Criterion) { }); } -static NUMBER_OBJECT_ACCESS: &str = r#" -new Number( - new Number( - new Number( - new Number(100).valueOf() - 10.5 - ).valueOf() + 100 - ).valueOf() * 1.6 -) -"#; +static NUMBER_OBJECT_ACCESS: &str = include_str!("bench_scripts/number_object_access.js"); fn number_object_access(c: &mut Criterion) { let realm = Realm::create(); @@ -475,15 +326,7 @@ fn number_object_access(c: &mut Criterion) { }); } -static BOOLEAN_OBJECT_ACCESS: &str = r#" -new Boolean( - !new Boolean( - new Boolean( - !(new Boolean(false).valueOf()) && (new Boolean(true).valueOf()) - ).valueOf() - ).valueOf() -).valueOf() -"#; +static BOOLEAN_OBJECT_ACCESS: &str = include_str!("bench_scripts/boolean_object_access.js"); fn boolean_object_access(c: &mut Criterion) { let realm = Realm::create(); @@ -499,15 +342,7 @@ fn boolean_object_access(c: &mut Criterion) { }); } -static STRING_OBJECT_ACCESS: &str = r#" -new String( - new String( - new String( - new String('Hello').valueOf() + new String(", world").valueOf() - ).valueOf() + '!' - ).valueOf() -).valueOf() -"#; +static STRING_OBJECT_ACCESS: &str = include_str!("bench_scripts/string_object_access.js"); fn string_object_access(c: &mut Criterion) { let realm = Realm::create(); @@ -523,9 +358,7 @@ fn string_object_access(c: &mut Criterion) { }); } -static ARITHMETIC_OPERATIONS: &str = r#" -((2 + 2) ** 3 / 100 - 5 ** 3 * -1000) ** 2 + 100 - 8 -"#; +static ARITHMETIC_OPERATIONS: &str = include_str!("bench_scripts/arithmetic_operations.js"); fn arithmetic_operations(c: &mut Criterion) { let realm = Realm::create(); diff --git a/boa/benches/full.rs b/boa/benches/full.rs index 4d228a114e..55dd5fab6e 100644 --- a/boa/benches/full.rs +++ b/boa/benches/full.rs @@ -10,11 +10,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; )] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -static SYMBOL_CREATION: &str = r#" -(function () { - return Symbol(); -})(); -"#; +static SYMBOL_CREATION: &str = include_str!("bench_scripts/symbol_creation.js"); fn symbol_creation(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -23,18 +19,7 @@ fn symbol_creation(c: &mut Criterion) { }); } -static FOR_LOOP: &str = r#" -(function () { - let b = "hello"; - for (let a = 10; a < 100; a += 5) { - if (a < 50) { - b += "world"; - } - } - - return b; -})(); -"#; +static FOR_LOOP: &str = include_str!("bench_scripts/for_loop.js"); fn for_loop(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -43,18 +28,7 @@ fn for_loop(c: &mut Criterion) { }); } -static FIBONACCI: &str = r#" -(function () { - let num = 12; - - function fib(n) { - if (n <= 1) return 1; - return fib(n - 1) + fib(n - 2); - } - - return fib(num); -})(); -"#; +static FIBONACCI: &str = include_str!("bench_scripts/fibonacci.js"); fn fibonacci(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -63,16 +37,7 @@ fn fibonacci(c: &mut Criterion) { }); } -static OBJECT_CREATION: &str = r#" -(function () { - let test = { - my_prop: "hello", - another: 65, - }; - - return test; -})(); -"#; +static OBJECT_CREATION: &str = include_str!("bench_scripts/object_creation.js"); fn object_creation(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -81,16 +46,7 @@ fn object_creation(c: &mut Criterion) { }); } -static OBJECT_PROP_ACCESS_CONST: &str = r#" -(function () { - let test = { - my_prop: "hello", - another: 65, - }; - - return test.my_prop; -})(); -"#; +static OBJECT_PROP_ACCESS_CONST: &str = include_str!("bench_scripts/object_prop_access_const.js"); fn object_prop_access_const(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -99,16 +55,7 @@ fn object_prop_access_const(c: &mut Criterion) { }); } -static OBJECT_PROP_ACCESS_DYN: &str = r#" -(function () { - let test = { - my_prop: "hello", - another: 65, - }; - - return test["my" + "_prop"]; -})(); -"#; +static OBJECT_PROP_ACCESS_DYN: &str = include_str!("bench_scripts/object_prop_access_dyn.js"); fn object_prop_access_dyn(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -117,13 +64,7 @@ fn object_prop_access_dyn(c: &mut Criterion) { }); } -static REGEXP_LITERAL_CREATION: &str = r#" -(function () { - let regExp = /hello/i; - - return regExp; -})(); -"#; +static REGEXP_LITERAL_CREATION: &str = include_str!("bench_scripts/regexp_literal_creation.js"); fn regexp_literal_creation(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -132,13 +73,7 @@ fn regexp_literal_creation(c: &mut Criterion) { }); } -static REGEXP_CREATION: &str = r#" -(function () { - let regExp = new RegExp('hello', 'i'); - - return regExp; -})(); -"#; +static REGEXP_CREATION: &str = include_str!("bench_scripts/regexp_creation.js"); fn regexp_creation(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -147,13 +82,7 @@ fn regexp_creation(c: &mut Criterion) { }); } -static REGEXP_LITERAL: &str = r#" -(function () { - let regExp = /hello/i; - - return regExp.test("Hello World"); -})(); -"#; +static REGEXP_LITERAL: &str = include_str!("bench_scripts/regexp_literal.js"); fn regexp_literal(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing @@ -162,28 +91,14 @@ fn regexp_literal(c: &mut Criterion) { }); } -static REGEXP: &str = r#" -(function () { - let regExp = new RegExp('hello', 'i'); - - return regExp.test("Hello World"); -})(); -"#; +static REGEXP: &str = include_str!("bench_scripts/regexp.js"); fn regexp(c: &mut Criterion) { // Execute the code by taking into account realm creation, lexing and parsing c.bench_function("RegExp (Full)", move |b| b.iter(|| exec(black_box(REGEXP)))); } -static ARRAY_ACCESS: &str = r#" -(function () { - let testArr = [1,2,3,4,5]; - - let res = testArr[2]; - - return res; -})(); -"#; +static ARRAY_ACCESS: &str = include_str!("bench_scripts/array_access.js"); fn array_access(c: &mut Criterion) { c.bench_function("Array access (Full)", move |b| { @@ -191,16 +106,7 @@ fn array_access(c: &mut Criterion) { }); } -static ARRAY_CREATE: &str = r#" -(function(){ - let testArr = []; - for (let a = 0; a <= 500; a++) { - testArr[a] = ('p' + a); - } - - return testArr; -})(); -"#; +static ARRAY_CREATE: &str = include_str!("bench_scripts/array_create.js"); fn array_creation(c: &mut Criterion) { c.bench_function("Array creation (Full)", move |b| { @@ -208,32 +114,7 @@ fn array_creation(c: &mut Criterion) { }); } -static ARRAY_POP: &str = r#" -(function(){ - let testArray = [83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, - 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, - 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, - 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, - 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, - 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, - 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, - 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, - 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, - 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, - 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, - 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, - 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28]; - - while (testArray.length > 0) { - testArray.pop(); - } - - return testArray; -})(); -"#; +static ARRAY_POP: &str = include_str!("bench_scripts/array_pop.js"); fn array_pop(c: &mut Criterion) { c.bench_function("Array pop (Full)", move |b| { @@ -241,14 +122,7 @@ fn array_pop(c: &mut Criterion) { }); } -static STRING_CONCAT: &str = r#" -(function(){ - var a = "hello"; - var b = "world"; - - var c = a + b; -})(); -"#; +static STRING_CONCAT: &str = include_str!("bench_scripts/string_concat.js"); fn string_concat(c: &mut Criterion) { c.bench_function("String concatenation (Full)", move |b| { @@ -256,17 +130,7 @@ fn string_concat(c: &mut Criterion) { }); } -static STRING_COMPARE: &str = r#" -(function(){ - var a = "hello"; - var b = "world"; - - var c = a == b; - - var d = b; - var e = d == b; -})(); -"#; +static STRING_COMPARE: &str = include_str!("bench_scripts/string_compare.js"); fn string_compare(c: &mut Criterion) { c.bench_function("String comparison (Full)", move |b| { @@ -274,12 +138,7 @@ fn string_compare(c: &mut Criterion) { }); } -static STRING_COPY: &str = r#" -(function(){ - var a = "hello"; - var b = a; -})(); -"#; +static STRING_COPY: &str = include_str!("bench_scripts/string_copy.js"); fn string_copy(c: &mut Criterion) { c.bench_function("String copy (Full)", move |b| { @@ -287,15 +146,7 @@ fn string_copy(c: &mut Criterion) { }); } -static NUMBER_OBJECT_ACCESS: &str = r#" -new Number( - new Number( - new Number( - new Number(100).valueOf() - 10.5 - ).valueOf() + 100 - ).valueOf() * 1.6 -) -"#; +static NUMBER_OBJECT_ACCESS: &str = include_str!("bench_scripts/number_object_access.js"); fn number_object_access(c: &mut Criterion) { c.bench_function("Number Object Access (Full)", move |b| { @@ -303,15 +154,7 @@ fn number_object_access(c: &mut Criterion) { }); } -static BOOLEAN_OBJECT_ACCESS: &str = r#" -new Boolean( - !new Boolean( - new Boolean( - !(new Boolean(false).valueOf()) && (new Boolean(true).valueOf()) - ).valueOf() - ).valueOf() -).valueOf() -"#; +static BOOLEAN_OBJECT_ACCESS: &str = include_str!("bench_scripts/boolean_object_access.js"); fn boolean_object_access(c: &mut Criterion) { c.bench_function("Boolean Object Access (Full)", move |b| { @@ -319,15 +162,7 @@ fn boolean_object_access(c: &mut Criterion) { }); } -static STRING_OBJECT_ACCESS: &str = r#" -new String( - new String( - new String( - new String('Hello').valueOf() + new String(", world").valueOf() - ).valueOf() + '!' - ).valueOf() -).valueOf() -"#; +static STRING_OBJECT_ACCESS: &str = include_str!("bench_scripts/string_object_access.js"); fn string_object_access(c: &mut Criterion) { c.bench_function("String Object Access (Full)", move |b| { @@ -335,9 +170,7 @@ fn string_object_access(c: &mut Criterion) { }); } -static ARITHMETIC_OPERATIONS: &str = r#" -((2 + 2) ** 3 / 100 - 5 ** 3 * -1000) ** 2 + 100 - 8 -"#; +static ARITHMETIC_OPERATIONS: &str = include_str!("bench_scripts/arithmetic_operations.js"); fn arithmetic_operations(c: &mut Criterion) { c.bench_function("Arithmetic operations (Full)", move |b| { diff --git a/boa/benches/lexer.rs b/boa/benches/lexer.rs index bd441e4905..a48865b914 100644 --- a/boa/benches/lexer.rs +++ b/boa/benches/lexer.rs @@ -10,9 +10,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; )] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -static EXPRESSION: &str = r#" -1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; -"#; +static EXPRESSION: &str = include_str!("bench_scripts/expression.js"); fn expression_lexer(c: &mut Criterion) { c.bench_function("Expression (Lexer)", move |b| { @@ -24,7 +22,7 @@ fn expression_lexer(c: &mut Criterion) { }); } -static HELLO_WORLD: &str = "let foo = 'hello world!'; foo;"; +static HELLO_WORLD: &str = include_str!("bench_scripts/hello_world.js"); fn hello_world_lexer(c: &mut Criterion) { c.bench_function("Hello World (Lexer)", move |b| { @@ -37,17 +35,7 @@ fn hello_world_lexer(c: &mut Criterion) { }); } -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"); - } -} -"#; +static FOR_LOOP: &str = include_str!("bench_scripts/for_loop.js"); fn for_loop_lexer(c: &mut Criterion) { c.bench_function("For loop (Lexer)", move |b| { diff --git a/boa/benches/parser.rs b/boa/benches/parser.rs index f70854fb81..ac9ab7586f 100644 --- a/boa/benches/parser.rs +++ b/boa/benches/parser.rs @@ -10,9 +10,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; )] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -static EXPRESSION: &str = r#" -1 + 1 + 1 + 1 + 1 + 1 / 1 + 1 + 1 * 1 + 1 + 1 + 1; -"#; +static EXPRESSION: &str = include_str!("bench_scripts/expression.js"); fn expression_parser(c: &mut Criterion) { // We include the lexing in the benchmarks, since they will get together soon, anyways. @@ -27,7 +25,7 @@ fn expression_parser(c: &mut Criterion) { }); } -static HELLO_WORLD: &str = "let foo = 'hello world!'; foo;"; +static HELLO_WORLD: &str = include_str!("bench_scripts/hello_world.js"); fn hello_world_parser(c: &mut Criterion) { // We include the lexing in the benchmarks, since they will get together soon, anyways. @@ -42,17 +40,7 @@ fn hello_world_parser(c: &mut Criterion) { }); } -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"); - } -} -"#; +static FOR_LOOP: &str = include_str!("bench_scripts/for_loop.js"); fn for_loop_parser(c: &mut Criterion) { // We include the lexing in the benchmarks, since they will get together soon, anyways. @@ -67,17 +55,7 @@ fn for_loop_parser(c: &mut Criterion) { }); } -static LONG_REPETITION: &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"); - } -} -"#; +static LONG_REPETITION: &str = include_str!("bench_scripts/long_repetition.js"); fn long_file_parser(c: &mut Criterion) { use std::{ @@ -111,15 +89,7 @@ fn long_file_parser(c: &mut Criterion) { fs::remove_file(FILE_NAME).unwrap_or_else(|_| panic!("could not remove {}", FILE_NAME)); } -static GOAL_SYMBOL_SWITCH: &str = r#" -function foo(regex, num) {} - -let i = 0; -while (i < 1000000) { - foo(/ab+c/, 5.0/5); - i++; -} -"#; +static GOAL_SYMBOL_SWITCH: &str = include_str!("bench_scripts/goal_symbol_switch.js"); fn goal_symbol_switch(c: &mut Criterion) { // We include the lexing in the benchmarks, since they will get together soon, anyways.