From 1ac5f205eb873c2aac8d665969776b4277caa2ba Mon Sep 17 00:00:00 2001 From: HalidOdat Date: Mon, 22 Jun 2020 09:42:13 +0200 Subject: [PATCH] Added arithmetic operation benchmark (#516) --- boa/benches/exec.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/boa/benches/exec.rs b/boa/benches/exec.rs index 5358f94f72..a60a64be51 100644 --- a/boa/benches/exec.rs +++ b/boa/benches/exec.rs @@ -523,6 +523,24 @@ fn string_object_access(c: &mut Criterion) { }); } +static ARITHMETIC_OPERATIONS: &str = r#" +((2 + 2) ** 3 / 100 - 5 ** 3 * -1000) ** 2 + 100 - 8 +"#; + +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)); + lexer.lex().expect("failed to lex"); + + let nodes = Parser::new(&black_box(lexer.tokens)).parse_all().unwrap(); + + c.bench_function("Arithmetic operations (Execution)", move |b| { + b.iter(|| black_box(&nodes).run(&mut engine).unwrap()) + }); +} + criterion_group!( execution, create_realm, @@ -545,5 +563,6 @@ criterion_group!( number_object_access, boolean_object_access, string_object_access, + arithmetic_operations, ); criterion_main!(execution);