Skip to content

Commit

Permalink
Code cleanup and inline (#916)
Browse files Browse the repository at this point in the history
* use gc module

* Added #[inline]

* Change context valiable names to context

* Fix test262

* Update test262 submodule

* Fix: Switch interpreter for context

Co-authored-by: João Borges <rageknify@gmail.com>
  • Loading branch information
HalidOdat and RageKnify authored Oct 29, 2020
1 parent ac6500c commit 6eac058
Show file tree
Hide file tree
Showing 109 changed files with 3,915 additions and 3,690 deletions.
98 changes: 44 additions & 54 deletions boa/benches/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ fn create_realm(c: &mut Criterion) {
static SYMBOL_CREATION: &str = include_str!("bench_scripts/symbol_creation.js");

fn symbol_creation(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(SYMBOL_CREATION.as_bytes(), false)
Expand All @@ -27,30 +26,28 @@ fn symbol_creation(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Symbols (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static FOR_LOOP: &str = include_str!("bench_scripts/for_loop.js");

fn for_loop_execution(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(FOR_LOOP.as_bytes(), false).parse_all().unwrap();

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("For loop (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static FIBONACCI: &str = include_str!("bench_scripts/fibonacci.js");

fn fibonacci(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(FIBONACCI.as_bytes(), false)
Expand All @@ -59,15 +56,14 @@ fn fibonacci(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Fibonacci (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static OBJECT_CREATION: &str = include_str!("bench_scripts/object_creation.js");

fn object_creation(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(OBJECT_CREATION.as_bytes(), false)
Expand All @@ -76,15 +72,14 @@ fn object_creation(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Object Creation (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

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.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(OBJECT_PROP_ACCESS_CONST.as_bytes(), false)
Expand All @@ -93,15 +88,14 @@ fn object_prop_access_const(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Static Object Property Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

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.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(OBJECT_PROP_ACCESS_DYN.as_bytes(), false)
Expand All @@ -110,15 +104,14 @@ fn object_prop_access_dyn(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Dynamic Object Property Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

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.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(REGEXP_LITERAL_CREATION.as_bytes(), false)
Expand All @@ -127,15 +120,14 @@ fn regexp_literal_creation(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("RegExp Literal Creation (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static REGEXP_CREATION: &str = include_str!("bench_scripts/regexp_creation.js");

fn regexp_creation(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(REGEXP_CREATION.as_bytes(), false)
Expand All @@ -144,15 +136,14 @@ fn regexp_creation(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("RegExp (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static REGEXP_LITERAL: &str = include_str!("bench_scripts/regexp_literal.js");

fn regexp_literal(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(REGEXP_LITERAL.as_bytes(), false)
Expand All @@ -161,182 +152,181 @@ fn regexp_literal(c: &mut Criterion) {

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("RegExp Literal (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static REGEXP: &str = include_str!("bench_scripts/regexp.js");

fn regexp(c: &mut Criterion) {
// Create new Realm and interpreter.
let mut engine = Context::new();
let mut context = Context::new();

// Parse the AST nodes.
let nodes = Parser::new(REGEXP.as_bytes(), false).parse_all().unwrap();

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("RegExp (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static ARRAY_ACCESS: &str = include_str!("bench_scripts/array_access.js");

fn array_access(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(ARRAY_ACCESS.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("Array access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static ARRAY_CREATE: &str = include_str!("bench_scripts/array_create.js");

fn array_creation(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(ARRAY_CREATE.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("Array creation (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static ARRAY_POP: &str = include_str!("bench_scripts/array_pop.js");

fn array_pop(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(ARRAY_POP.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("Array pop (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static STRING_CONCAT: &str = include_str!("bench_scripts/string_concat.js");

fn string_concat(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(STRING_CONCAT.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("String concatenation (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static STRING_COMPARE: &str = include_str!("bench_scripts/string_compare.js");

fn string_compare(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(STRING_COMPARE.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("String comparison (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static STRING_COPY: &str = include_str!("bench_scripts/string_copy.js");

fn string_copy(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(STRING_COPY.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("String copy (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static NUMBER_OBJECT_ACCESS: &str = include_str!("bench_scripts/number_object_access.js");

fn number_object_access(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(NUMBER_OBJECT_ACCESS.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("Number Object Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static BOOLEAN_OBJECT_ACCESS: &str = include_str!("bench_scripts/boolean_object_access.js");

fn boolean_object_access(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(BOOLEAN_OBJECT_ACCESS.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("Boolean Object Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static STRING_OBJECT_ACCESS: &str = include_str!("bench_scripts/string_object_access.js");

fn string_object_access(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(STRING_OBJECT_ACCESS.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("String Object Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static ARITHMETIC_OPERATIONS: &str = include_str!("bench_scripts/arithmetic_operations.js");

fn arithmetic_operations(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();

let nodes = Parser::new(ARITHMETIC_OPERATIONS.as_bytes(), false)
.parse_all()
.unwrap();

c.bench_function("Arithmetic operations (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static CLEAN_JS: &str = include_str!("bench_scripts/clean_js.js");

fn clean_js(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();
let nodes = Parser::new(CLEAN_JS.as_bytes(), false).parse_all().unwrap();
c.bench_function("Clean js (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

static MINI_JS: &str = include_str!("bench_scripts/mini_js.js");

fn mini_js(c: &mut Criterion) {
let mut engine = Context::new();
let mut context = Context::new();
let nodes = Parser::new(MINI_JS.as_bytes(), false).parse_all().unwrap();
c.bench_function("Mini js (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

Expand Down
Loading

0 comments on commit 6eac058

Please sign in to comment.