var count = 100000
function runCount(f) {
for(i=0; i<count; i++){f()}
}
runCount(() => ( {} ));
runCount(() => ( () => {} ));
runCount(() => ( () => ({}) ));
runCount(() => ( { open: () => {}, close: () => {} } ));
runCount(() => ( () => ({ open: () => {}, close: () => {} }) ));
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
create empty object | |
create empty function | |
create function returns object | |
create object with 2 functions | |
create function returns object with 2 funcitons |
Test name | Executions per second |
---|---|
create empty object | 375.2 Ops/sec |
create empty function | 376.3 Ops/sec |
create function returns object | 386.8 Ops/sec |
create object with 2 functions | 303.2 Ops/sec |
create function returns object with 2 funcitons | 385.5 Ops/sec |
Let's break down what's being tested in this benchmark.
Benchmark Definition
The benchmark is defined by the script preparation code: var count = 100000\r\nfunction runCount(f) {\r\n\tfor(i=0; i<count; i++){f()}\r\n}
. This code sets up a loop that will execute a provided function f
100,000 times.
Benchmark Variations The benchmark has five test cases, each defining a different approach to creating and executing functions or objects:
runCount(() => ( {} ));
runCount(() => ( () => {} ));
runCount(() => ( () => ({}) ));
runCount(() => ( { open: () => {}, close: () => {} } ));
runCount(() => ( () => ({ open: () => {}, close: () => {} }) ));
Options Compared
Each test case is comparing the performance of different approaches to creating and executing functions or objects:
Pros and Cons
Here's a brief summary of the pros and cons of each approach:
Library Usage
None of the benchmark tests explicitly use any external libraries. However, it's worth noting that forEach
loop used in the runCount
function is a built-in method in JavaScript, which may be optimized by the browser engine for performance reasons.
Special JS Features or Syntax This benchmark does not use any special JavaScript features or syntax beyond what's commonly found in modern browsers. However, it's worth noting that some of these features (e.g., arrow functions, template literals) are supported by many browsers but may have different behavior or performance characteristics depending on the engine and version.
Alternatives
Other alternatives for benchmarking similar code could include: