mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
4.4 KiB
130 lines
4.4 KiB
1 year ago
|
#![allow(unused_crate_dependencies, missing_docs)]
|
||
|
|
||
3 years ago
|
//! Benchmarks of the whole execution engine in Boa.
|
||
4 years ago
|
|
||
2 years ago
|
use boa_engine::{
|
||
2 years ago
|
context::DefaultHooks, object::shape::RootShape, optimizer::OptimizerOptions, realm::Realm,
|
||
2 years ago
|
script::Script, Context, Source,
|
||
2 years ago
|
};
|
||
2 years ago
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||
|
use std::hint::black_box;
|
||
4 years ago
|
|
||
|
#[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;
|
||
|
|
||
3 years ago
|
fn create_realm(c: &mut Criterion) {
|
||
2 years ago
|
c.bench_function("Create Realm", move |b| {
|
||
2 years ago
|
let root_shape = RootShape::default();
|
||
1 year ago
|
b.iter(|| Realm::create(&DefaultHooks, &root_shape));
|
||
2 years ago
|
});
|
||
3 years ago
|
}
|
||
|
|
||
|
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"));
|
||
3 years ago
|
let mut context = Context::default();
|
||
2 years ago
|
|
||
|
// Disable optimizations
|
||
|
context.set_optimizer_options(OptimizerOptions::empty());
|
||
|
|
||
3 years ago
|
c.bench_function(concat!($id, " (Parser)"), move |b| {
|
||
2 years ago
|
b.iter(|| {
|
||
|
Script::parse(
|
||
|
black_box(Source::from_bytes(CODE)),
|
||
|
None,
|
||
|
&mut context,
|
||
|
).unwrap()
|
||
|
})
|
||
3 years ago
|
});
|
||
|
}
|
||
|
)*
|
||
|
}
|
||
|
fn bench_compile(c: &mut Criterion) {
|
||
|
$(
|
||
|
{
|
||
|
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
|
||
2 years ago
|
let context = &mut Context::default();
|
||
2 years ago
|
|
||
|
// Disable optimizations
|
||
|
context.set_optimizer_options(OptimizerOptions::empty());
|
||
|
|
||
2 years ago
|
let script = Script::parse(
|
||
|
black_box(Source::from_bytes(CODE)),
|
||
|
None,
|
||
|
context,
|
||
|
).unwrap();
|
||
3 years ago
|
c.bench_function(concat!($id, " (Compiler)"), move |b| {
|
||
|
b.iter(|| {
|
||
2 years ago
|
script.codeblock(context).unwrap()
|
||
3 years ago
|
})
|
||
|
});
|
||
|
}
|
||
|
)*
|
||
|
}
|
||
|
fn bench_execution(c: &mut Criterion) {
|
||
|
$(
|
||
|
{
|
||
|
static CODE: &str = include_str!(concat!("bench_scripts/", stringify!($name), ".js"));
|
||
2 years ago
|
let context = &mut Context::default();
|
||
2 years ago
|
|
||
|
// Disable optimizations
|
||
|
context.set_optimizer_options(OptimizerOptions::empty());
|
||
|
|
||
2 years ago
|
let script = Script::parse(
|
||
|
black_box(Source::from_bytes(CODE)),
|
||
|
None,
|
||
|
context,
|
||
|
).unwrap();
|
||
|
script.codeblock(context).unwrap();
|
||
3 years ago
|
c.bench_function(concat!($id, " (Execution)"), move |b| {
|
||
|
b.iter(|| {
|
||
2 years ago
|
script.evaluate(context).unwrap();
|
||
3 years ago
|
})
|
||
|
});
|
||
|
}
|
||
|
)*
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
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}
|
||
|
);
|
||
4 years ago
|
|
||
4 years ago
|
criterion_group!(
|
||
3 years ago
|
benches,
|
||
|
create_realm,
|
||
|
bench_parser,
|
||
|
bench_compile,
|
||
|
bench_execution,
|
||
4 years ago
|
);
|
||
3 years ago
|
criterion_main!(benches);
|