Skip to content

Commit

Permalink
Added benchmarks for full program execution (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
Razican authored Jul 10, 2020
1 parent 8b3d52b commit 6a721f9
Show file tree
Hide file tree
Showing 3 changed files with 415 additions and 40 deletions.
4 changes: 4 additions & 0 deletions boa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ harness = false
[[bench]]
name = "exec"
harness = false

[[bench]]
name = "full"
harness = false
80 changes: 40 additions & 40 deletions boa/benches/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fn symbol_creation(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(SYMBOL_CREATION));
let mut lexer = Lexer::new(SYMBOL_CREATION);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Symbols (Execution)", move |b| {
Expand All @@ -57,11 +57,11 @@ fn for_loop_execution(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(FOR_LOOP));
let mut lexer = Lexer::new(FOR_LOOP);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).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| {
Expand All @@ -88,11 +88,11 @@ fn fibonacci(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(FIBONACCI));
let mut lexer = Lexer::new(FIBONACCI);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// Execute the parsed nodes, passing them through a black box, to avoid over-optimizing by the compiler
c.bench_function("Fibonacci (Execution)", move |b| {
Expand All @@ -117,11 +117,11 @@ fn object_creation(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(OBJECT_CREATION));
let mut lexer = Lexer::new(OBJECT_CREATION);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// 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| {
Expand All @@ -146,11 +146,11 @@ fn object_prop_access_const(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(OBJECT_PROP_ACCESS_CONST));
let mut lexer = Lexer::new(OBJECT_PROP_ACCESS_CONST);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// 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| {
Expand All @@ -175,11 +175,11 @@ fn object_prop_access_dyn(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(OBJECT_PROP_ACCESS_DYN));
let mut lexer = Lexer::new(OBJECT_PROP_ACCESS_DYN);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// 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| {
Expand All @@ -201,11 +201,11 @@ fn regexp_literal_creation(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(REGEXP_LITERAL_CREATION));
let mut lexer = Lexer::new(REGEXP_LITERAL_CREATION);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// 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| {
Expand All @@ -227,11 +227,11 @@ fn regexp_creation(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(REGEXP_CREATION));
let mut lexer = Lexer::new(REGEXP_CREATION);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).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| {
Expand All @@ -253,11 +253,11 @@ fn regexp_literal(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(REGEXP_LITERAL));
let mut lexer = Lexer::new(REGEXP_LITERAL);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

// 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| {
Expand All @@ -279,11 +279,11 @@ fn regexp(c: &mut Criterion) {
let mut engine = Interpreter::new(realm);

// Lex all the tokens.
let mut lexer = Lexer::new(black_box(REGEXP));
let mut lexer = Lexer::new(REGEXP);
lexer.lex().expect("failed to lex");

// Parse the AST nodes.
let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).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| {
Expand All @@ -305,10 +305,10 @@ fn array_access(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(ARRAY_ACCESS));
let mut lexer = Lexer::new(ARRAY_ACCESS);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("Array access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -330,10 +330,10 @@ fn array_creation(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(ARRAY_CREATE));
let mut lexer = Lexer::new(ARRAY_CREATE);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("Array creation (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand Down Expand Up @@ -371,10 +371,10 @@ fn array_pop(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(ARRAY_POP));
let mut lexer = Lexer::new(ARRAY_POP);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("Array pop (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -394,10 +394,10 @@ fn string_concat(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(STRING_CONCAT));
let mut lexer = Lexer::new(STRING_CONCAT);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("String concatenation (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -420,10 +420,10 @@ fn string_compare(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(STRING_COMPARE));
let mut lexer = Lexer::new(STRING_COMPARE);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("String comparison (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -441,10 +441,10 @@ fn string_copy(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(STRING_COPY));
let mut lexer = Lexer::new(STRING_COPY);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("String copy (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -465,10 +465,10 @@ fn number_object_access(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(NUMBER_OBJECT_ACCESS));
let mut lexer = Lexer::new(NUMBER_OBJECT_ACCESS);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("Number Object Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -489,10 +489,10 @@ fn boolean_object_access(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(BOOLEAN_OBJECT_ACCESS));
let mut lexer = Lexer::new(BOOLEAN_OBJECT_ACCESS);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("Boolean Object Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -513,10 +513,10 @@ fn string_object_access(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(STRING_OBJECT_ACCESS));
let mut lexer = Lexer::new(STRING_OBJECT_ACCESS);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("String Object Access (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand All @@ -531,10 +531,10 @@ fn arithmetic_operations(c: &mut Criterion) {
let realm = Realm::create();
let mut engine = Interpreter::new(realm);

let mut lexer = Lexer::new(black_box(ARITHMETIC_OPERATIONS));
let mut lexer = Lexer::new(ARITHMETIC_OPERATIONS);
lexer.lex().expect("failed to lex");

let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap();
let nodes = Parser::new(&lexer.tokens).parse_all().unwrap();

c.bench_function("Arithmetic operations (Execution)", move |b| {
b.iter(|| black_box(&nodes).run(&mut engine).unwrap())
Expand Down
Loading

0 comments on commit 6a721f9

Please sign in to comment.