feat: works
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# Boa Benchmarks
|
||||
|
||||
For each js script in the `bench_scripts` folder, we create three benchmarks:
|
||||
|
||||
- Parser => lexing and parsing of the source code
|
||||
- Compiler => compilation of the parsed statement list into bytecode
|
||||
- Execution => execution of the bytecode in the vm
|
||||
|
||||
The idea is to check the performance of Boa in different scenarios.
|
||||
Different parts of Boa are benchmarked separately to make the impact of local changes visible.
|
||||
@@ -0,0 +1 @@
|
||||
((2 + 2) ** 3 / 100 - 5 ** 3 * -1000) ** 2 + 100 - 8;
|
||||
@@ -0,0 +1,7 @@
|
||||
(function () {
|
||||
let testArr = [1, 2, 3, 4, 5];
|
||||
|
||||
let res = testArr[2];
|
||||
|
||||
return res;
|
||||
})();
|
||||
@@ -0,0 +1,8 @@
|
||||
(function () {
|
||||
let testArr = [];
|
||||
for (let a = 0; a <= 500; a++) {
|
||||
testArr[a] = "p" + a;
|
||||
}
|
||||
|
||||
return testArr;
|
||||
})();
|
||||
@@ -0,0 +1,22 @@
|
||||
(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;
|
||||
})();
|
||||
@@ -0,0 +1,7 @@
|
||||
new Boolean(
|
||||
!new Boolean(
|
||||
new Boolean(
|
||||
!new Boolean(false).valueOf() && new Boolean(true).valueOf()
|
||||
).valueOf()
|
||||
).valueOf()
|
||||
).valueOf();
|
||||
@@ -0,0 +1,15 @@
|
||||
!function () {
|
||||
var M = new Array();
|
||||
for (i = 0; i < 100; i++) {
|
||||
M.push(Math.floor(Math.random() * 100));
|
||||
}
|
||||
var test = [];
|
||||
for (i = 0; i < 100; i++) {
|
||||
if (M[i] > 50) {
|
||||
test.push(M[i]);
|
||||
}
|
||||
}
|
||||
test.forEach(elem => {
|
||||
0
|
||||
});
|
||||
}();
|
||||
@@ -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);
|
||||
})();
|
||||
@@ -0,0 +1,10 @@
|
||||
(function () {
|
||||
let b = "hello";
|
||||
for (let a = 10; a < 100; a += 5) {
|
||||
if (a < 50) {
|
||||
b += "world";
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
})();
|
||||
@@ -0,0 +1 @@
|
||||
!function(){var r=new Array();for(i=0;i<100;i++)r.push(Math.floor(100*Math.random()));var a=[];for(i=0;i<100;i++)r[i]>50&&a.push(r[i]);a.forEach(i=>{0})}();
|
||||
@@ -0,0 +1,5 @@
|
||||
new Number(
|
||||
new Number(
|
||||
new Number(new Number(100).valueOf() - 10.5).valueOf() + 100
|
||||
).valueOf() * 1.6
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
(function () {
|
||||
let test = {
|
||||
my_prop: "hello",
|
||||
another: 65,
|
||||
};
|
||||
|
||||
return test;
|
||||
})();
|
||||
@@ -0,0 +1,8 @@
|
||||
(function () {
|
||||
let test = {
|
||||
my_prop: "hello",
|
||||
another: 65,
|
||||
};
|
||||
|
||||
return test.my_prop;
|
||||
})();
|
||||
@@ -0,0 +1,8 @@
|
||||
(function () {
|
||||
let test = {
|
||||
my_prop: "hello",
|
||||
another: 65,
|
||||
};
|
||||
|
||||
return test["my" + "_prop"];
|
||||
})();
|
||||
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
let regExp = new RegExp("hello", "i");
|
||||
|
||||
return regExp.test("Hello World");
|
||||
})();
|
||||
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
let regExp = new RegExp("hello", "i");
|
||||
|
||||
return regExp;
|
||||
})();
|
||||
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
let regExp = /hello/i;
|
||||
|
||||
return regExp.test("Hello World");
|
||||
})();
|
||||
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
let regExp = /hello/i;
|
||||
|
||||
return regExp;
|
||||
})();
|
||||
@@ -0,0 +1,9 @@
|
||||
(function () {
|
||||
var a = "hello";
|
||||
var b = "world";
|
||||
|
||||
var c = a == b;
|
||||
|
||||
var d = b;
|
||||
var e = d == b;
|
||||
})();
|
||||
@@ -0,0 +1,6 @@
|
||||
(function () {
|
||||
var a = "hello";
|
||||
var b = "world";
|
||||
|
||||
var c = a + b;
|
||||
})();
|
||||
@@ -0,0 +1,4 @@
|
||||
(function () {
|
||||
var a = "hello";
|
||||
var b = a;
|
||||
})();
|
||||
@@ -0,0 +1,7 @@
|
||||
new String(
|
||||
new String(
|
||||
new String(
|
||||
new String("Hello").valueOf() + new String(", world").valueOf()
|
||||
).valueOf() + "!"
|
||||
).valueOf()
|
||||
).valueOf();
|
||||
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
return Symbol();
|
||||
})();
|
||||
@@ -0,0 +1,94 @@
|
||||
//! Benchmarks of the whole execution engine in Boa.
|
||||
|
||||
use boa_engine::{realm::Realm, Context};
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))]
|
||||
#[cfg_attr(
|
||||
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
|
||||
global_allocator
|
||||
)]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
fn create_realm(c: &mut Criterion) {
|
||||
c.bench_function("Create Realm", move |b| b.iter(Realm::create));
|
||||
}
|
||||
|
||||
macro_rules! full_benchmarks {
|
||||
($({$id:literal, $name:ident}),*) => {
|
||||
fn bench_parser(c: &mut Criterion) {
|
||||
$(
|
||||
{
|
||||
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
|
||||
let mut context = Context::default();
|
||||
c.bench_function(concat!($id, " (Parser)"), move |b| {
|
||||
b.iter(|| context.parse(black_box(CODE)))
|
||||
});
|
||||
}
|
||||
)*
|
||||
}
|
||||
fn bench_compile(c: &mut Criterion) {
|
||||
$(
|
||||
{
|
||||
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
|
||||
let mut context = Context::default();
|
||||
let statement_list = context.parse(CODE).expect("parsing failed");
|
||||
c.bench_function(concat!($id, " (Compiler)"), move |b| {
|
||||
b.iter(|| {
|
||||
context.compile(black_box(&statement_list))
|
||||
})
|
||||
});
|
||||
}
|
||||
)*
|
||||
}
|
||||
fn bench_execution(c: &mut Criterion) {
|
||||
$(
|
||||
{
|
||||
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
|
||||
let mut context = Context::default();
|
||||
let statement_list = context.parse(CODE).expect("parsing failed");
|
||||
let code_block = context.compile(&statement_list).unwrap();
|
||||
c.bench_function(concat!($id, " (Execution)"), move |b| {
|
||||
b.iter(|| {
|
||||
context.execute(black_box(code_block.clone())).unwrap()
|
||||
})
|
||||
});
|
||||
}
|
||||
)*
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
full_benchmarks!(
|
||||
{"Symbols", symbol_creation},
|
||||
{"For loop", for_loop},
|
||||
{"Fibonacci", fibonacci},
|
||||
{"Object Creation", object_creation},
|
||||
{"Static Object Property Access", object_prop_access_const},
|
||||
{"Dynamic Object Property Access", object_prop_access_dyn},
|
||||
{"RegExp Literal Creation", regexp_literal_creation},
|
||||
{"RegExp Creation", regexp_creation},
|
||||
{"RegExp Literal", regexp_literal},
|
||||
{"RegExp", regexp},
|
||||
{"Array access", array_access},
|
||||
{"Array creation", array_create},
|
||||
{"Array pop", array_pop},
|
||||
{"String concatenation", string_concat},
|
||||
{"String comparison", string_compare},
|
||||
{"String copy", string_copy},
|
||||
{"Number Object Access", number_object_access},
|
||||
{"Boolean Object Access", boolean_object_access},
|
||||
{"String Object Access", string_object_access},
|
||||
{"Arithmetic operations", arithmetic_operations},
|
||||
{"Clean js", clean_js},
|
||||
{"Mini js", mini_js}
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
create_realm,
|
||||
bench_parser,
|
||||
bench_compile,
|
||||
bench_execution,
|
||||
);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user