Browse Source

Added CLEAN_JS and MINI_JS benches (#581)

* Added CLEAN_JS and MINI_JS benches

These benches are arbitrary code which is subject to change,
functionally the programs are identical.

* Forgot semicolon

* Adding parsing benchmarks for CleanJS & MiniJS

Added identical benchmark cases for parser.

* Migrating Clean and Mini benchmarks to new format

Adding js scripts in bench_scripts & moving exec, full and parser
benchmarks to new include_str!() macro.
pull/653/head
neeldug 4 years ago committed by GitHub
parent
commit
4009204bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      boa/benches/bench_scripts/clean_js.js
  2. 1
      boa/benches/bench_scripts/mini_js.js
  3. 28
      boa/benches/exec.rs
  4. 18
      boa/benches/full.rs
  5. 28
      boa/benches/parser.rs

15
boa/benches/bench_scripts/clean_js.js

@ -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
});
}();

1
boa/benches/bench_scripts/mini_js.js

@ -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})}();

28
boa/benches/exec.rs

@ -374,6 +374,32 @@ fn arithmetic_operations(c: &mut Criterion) {
}); });
} }
static CLEAN_JS: &str = include_str!("bench_scripts/clean_js.js");
fn clean_js(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
let mut lexer = Lexer::new(CLEAN_JS);
lexer.lex().expect("failed to lex");
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();
c.bench_function("Clean js (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
});
}
static MINI_JS: &str = include_str!("bench_scripts/mini_js.js");
fn mini_js(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);
let mut lexer = Lexer::new(MINI_JS);
lexer.lex().expect("failed to lex");
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();
c.bench_function("Mini js (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
});
}
criterion_group!( criterion_group!(
execution, execution,
create_realm, create_realm,
@ -397,5 +423,7 @@ criterion_group!(
boolean_object_access, boolean_object_access,
string_object_access, string_object_access,
arithmetic_operations, arithmetic_operations,
clean_js,
mini_js,
); );
criterion_main!(execution); criterion_main!(execution);

18
boa/benches/full.rs

@ -178,6 +178,22 @@ fn arithmetic_operations(c: &mut Criterion) {
}); });
} }
static CLEAN_JS: &str = include_str!("bench_scripts/clean_js.js");
fn clean_js(c: &mut Criterion) {
c.bench_function("Clean js (Full)", move |b| {
b.iter(|| exec(black_box(CLEAN_JS)))
});
}
static MINI_JS: &str = include_str!("bench_scripts/mini_js.js");
fn mini_js(c: &mut Criterion) {
c.bench_function("Mini js (Full)", move |b| {
b.iter(|| exec(black_box(MINI_JS)))
});
}
criterion_group!( criterion_group!(
full, full,
symbol_creation, symbol_creation,
@ -200,5 +216,7 @@ criterion_group!(
boolean_object_access, boolean_object_access,
string_object_access, string_object_access,
arithmetic_operations, arithmetic_operations,
clean_js,
mini_js,
); );
criterion_main!(full); criterion_main!(full);

28
boa/benches/parser.rs

@ -104,6 +104,32 @@ fn goal_symbol_switch(c: &mut Criterion) {
}); });
} }
static CLEAN_JS: &str = include_str!("bench_scripts/clean_js.js");
fn clean_js(c: &mut Criterion) {
c.bench_function("Clean js (Parser)", move |b| {
b.iter(|| {
let mut lexer = Lexer::new(black_box(CLEAN_JS));
lexer.lex().expect("failed to lex");
Parser::new(&black_box(lexer.tokens)).parse_all()
})
});
}
static MINI_JS: &str = include_str!("bench_scripts/mini_js.js");
fn mini_js(c: &mut Criterion) {
c.bench_function("Mini js (Parser)", move |b| {
b.iter(|| {
let mut lexer = Lexer::new(black_box(MINI_JS));
lexer.lex().expect("failed to lex");
Parser::new(&black_box(lexer.tokens)).parse_all()
})
});
}
criterion_group!( criterion_group!(
parser, parser,
expression_parser, expression_parser,
@ -111,5 +137,7 @@ criterion_group!(
for_loop_parser, for_loop_parser,
long_file_parser, long_file_parser,
goal_symbol_switch, goal_symbol_switch,
clean_js,
mini_js,
); );
criterion_main!(parser); criterion_main!(parser);

Loading…
Cancel
Save