var arr = [100,324,234,234,2,4,4,23,423,42,5,34,63,45,354,23,525,235,23,52,35,235,2,352,35,2,35,235,23,52,53,25,2,35,23,52,35,25235,235,23,52,52,35,235,23,525]
arr.push(2)
arr = [arr, 2]
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.push | |
Array spread |
Test name | Executions per second |
---|---|
Array.push | 6232642.0 Ops/sec |
Array spread | 3.2 Ops/sec |
Let's break down what is tested on the provided JSON benchmark and explain the different approaches compared.
Benchmark Purpose
The primary goal of this benchmark is to compare the performance of two ways to add an element to an array in JavaScript:
push()
method...
)Options Compared
Two options are being compared:
arr.push(2)
push()
method, which adds a new element to the end of the array.arr = [...arr, 2]
[2]
.push()
because of the overhead of creating a new array.Pros and Cons
arr.push(2)
arr = [...arr, 2]
push()
Library Used
None is explicitly mentioned in this benchmark. However, if we look at the "Script Preparation Code", we can see that it's defining a variable arr
and initializing it with an array of numbers.
Special JS Feature/Syntax
There are no special JavaScript features or syntax used in this benchmark other than the use of spread operator (...
).