Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
spread vs arr
(version: 0)
Benchmark.js
aaa
Comparing performance of:
spread vs arr
Created:
6 years ago
by:
Guest
Go to the latest result
Tests:
spread
const spread = [1, 2, ...['a', true, 2]]
arr
const spread = [1, 2].push('a', true, 2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
spread
arr
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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
arr
74.4M/s
spread
54.9M/s
View exact numbers
Test name
Executions per second
✓
arr
74,383,480 Ops/sec
spread
54,934,952 Ops/sec
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's dive into the details of this benchmark test. **What is being tested?** This test compares two different ways to create an array in JavaScript: using the spread operator (`...`) and using the `push()` method on an existing array. **The options being compared are:** 1. **Spread Operator (`...`)**: This is a feature introduced in ECMAScript 2015 (ES6) that allows you to "spread" the elements of an iterable (like an array or a string) into a new array. The benchmark defines this as `"const spread = [1, 2, ...['a', true, 2]]";` 2. **`push()` method**: This is a standard JavaScript method that adds one or more elements to the end of an existing array. The benchmark defines this as `"const spread = [1, 2].push('a', true, 2)"`. **Pros and Cons:** * **Spread Operator (`...`)**: + Pros: Can create new arrays with initial values from iterables in a concise way. + Cons: May be slower than using `push()` for large arrays, as it involves creating a new array and iterating over the elements of the original iterable. * **`push()` method**: + Pros: Often faster than spread operator for large arrays, as it modifies an existing array instead of creating a new one. + Cons: May require more code to achieve the same result as the spread operator. **Other considerations:** * The benchmark uses a Chrome 80 browser on a Windows desktop platform. Results may vary depending on the specific browser, device, and operating system used. * The test cases use no external libraries or special JavaScript features beyond what is described above. **Library usage:** None in this case. **Special JS feature or syntax:** Only the spread operator (`...`) is being tested, which was introduced in ECMAScript 2015 (ES6). **Other alternatives:** If you need to create an array with initial values from an iterable, you can also use: * The `concat()` method: `[1, 2].concat(['a', true, 2])` * A loop or `for...of` statement: `[1, 2]; for (const value of ['a', true, 2]) { arr.push(value); }` Keep in mind that these alternatives may have different performance characteristics and use cases compared to the spread operator.
Related benchmarks
Array spread vs. push performance
Array .push() vs .unshift() vs spread
Array.prototype.slice vs spread operator performance
Comments
Confirm delete:
Do you really want to delete benchmark?