Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Spread Operator vs Push Method
(version: 0)
Comparing performance of:
Spread vs Push
Created:
3 years ago
by:
Guest
Go to the latest result
Tests:
Spread
const array = new Array(100) const value = "Addition" let newArray = [...array, value]
Push
const array = new Array(100) const value = "Addition" let newArray = array.push(value)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Spread
Push
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Push
13.0M/s
Spread
6.0M/s
View exact numbers
Test name
Executions per second
✓
Push
12,985,722 Ops/sec
Spread
5,967,504 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down the benchmark test case. **Benchmark Name:** Spread Operator vs Push Method **Description:** This test compares the performance of two methods to add an element to the end of an array: using the spread operator (`[...]`) and using the `push()` method. **Test Cases:** 1. **Spread** * Code: ```javascript const array = new Array(100) const value = "Addition" let newArray = [...array, value] ``` * This test uses the spread operator to create a new array by concatenating the original `array` with the `value`. 2. **Push** * Code: ```javascript const array = new Array(100) const value = "Addition" let newArray = array.push(value) ``` * This test uses the `push()` method to add the `value` to the end of the `array`, and returns the new length of the array. **Latest Benchmark Results:** The test results show that, on average: * **Push**: 1.25 million executions per second * **Spread**: 7.20 million executions per second **What's being tested:** In this benchmark, we're testing how quickly each method can add an element to the end of a large array (100 elements). The results show that using the spread operator is significantly faster than using the `push()` method. **Pros and Cons:** * **Spread Operator:** + Pros: - Faster execution time - Simple syntax + Cons: - Creates a new array, which can be memory-intensive for large arrays - May not be suitable for use cases where the original array needs to remain unchanged * **Push Method:** + Pros: - Modifies the original array in place - Can be more efficient when working with very large arrays + Cons: - Slower execution time compared to spread operator - May not be suitable for use cases where a new array is required **Other Considerations:** * When working with small arrays, the performance difference between `push()` and the spread operator may be negligible. * If you need to add multiple elements to an array, using the spread operator can be more efficient than calling `push()` repeatedly. **Library/Feature Used:** None, this test uses only standard JavaScript features. **Alternatives:** Other ways to add an element to the end of an array include: 1. Using the `concat()` method: ```javascript let newArray = array.concat([value]); ``` 2. Using a loop to push elements individually: ```javascript for (let i = 0; i < 100; i++) { array.push(value); } ``` Note that these alternatives may have their own performance trade-offs and are not recommended as substitutes for the spread operator or `push()` method in most cases.
Related benchmarks
Math.pow() vs exponentiation operator
Math.pow(x,0.5) vs Math.sqrt(x) vs x**
math pow vs bit shifting vs exponentiation operator
Math.pow(x,0.5) vs Math.sqrt(x) 12
(x ** 0.5) vs Math.sqrt(x)
Comments
Confirm delete:
Do you really want to delete benchmark?