var arr = new Array();
var arr = [];
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array constructor - 10 items | |
Array literal (assign by index) - 10 items |
Test name | Executions per second |
---|---|
Array constructor - 10 items | 16623015.0 Ops/sec |
Array literal (assign by index) - 10 items | 234986352.0 Ops/sec |
Let's break down the test cases and explain what is being tested.
What are we testing?
We're comparing two approaches to create an empty array in JavaScript: using the Array
constructor (new Array()
) versus literal syntax ([]
). The goal is to measure which approach performs better.
Options compared:
var arr = new Array();
var arr = [];
Pros and Cons of each approach:
Array
constructor.Other considerations:
Special JavaScript features/syntax:
There are no special JavaScript features or syntax used in this benchmark.
Libraries and dependencies:
None mentioned in the provided information.
Alternatives:
Other approaches to create an empty array include:
Array()
function with the new
keyword (e.g., var arr = new Array(10)
).[]
into new Array()
._.empty()
).The test cases provided by MeasureThat.net focus on the fundamental difference between using the Array
constructor and literal syntax to create an empty array.