Skip to content

Commit

Permalink
adds benchmark for concat
Browse files Browse the repository at this point in the history
  • Loading branch information
neeldug committed Jul 27, 2021
1 parent c290767 commit 0d59dad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions boa/benches/bench_scripts/array_concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(function () {
let arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
let arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

let arr3 = arr1.concat(arr2);
})();
11 changes: 11 additions & 0 deletions boa/benches/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ fn mini_js(c: &mut Criterion) {
});
}

static ARRAY_CONCAT: &str = include_str!("bench_scripts/array_concat.js");

fn array_concat(c: &mut Criterion) {
let mut context = Context::new();
let nodes = Parser::new(ARRAY_CONCAT.as_bytes(), false).parse_all().unwrap();
c.bench_function("Array concat (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut context).unwrap())
});
}

criterion_group!(
execution,
create_realm,
Expand All @@ -355,5 +365,6 @@ criterion_group!(
arithmetic_operations,
clean_js,
mini_js,
array_concat,
);
criterion_main!(execution);
9 changes: 9 additions & 0 deletions boa/benches/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ fn mini_js(c: &mut Criterion) {
});
}

static ARRAY_CONCAT: &str = include_str!("bench_scripts/array_concat.js");

fn array_concat(c: &mut Criterion) {
c.bench_function("Array concat (Full)", move |b| {
b.iter(|| Context::new().eval(black_box(ARRAY_CONCAT)))
});
}

criterion_group!(
full,
symbol_creation,
Expand All @@ -220,5 +228,6 @@ criterion_group!(
arithmetic_operations,
clean_js,
mini_js,
array_concat,
);
criterion_main!(full);
9 changes: 9 additions & 0 deletions boa/benches/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ fn mini_js(c: &mut Criterion) {
});
}

static ARRAY_CONCAT: &str = include_str!("bench_scripts/array_concat.js");

fn array_concat(c: &mut Criterion) {
c.bench_function("Array concat (Parser)", move |b| {
b.iter(|| Parser::new(black_box(ARRAY_CONCAT.as_bytes()), false).parse_all())
});
}

criterion_group!(
parser,
expression_parser,
Expand All @@ -95,5 +103,6 @@ criterion_group!(
goal_symbol_switch,
clean_js,
mini_js,
array_concat,
);
criterion_main!(parser);

0 comments on commit 0d59dad

Please sign in to comment.