Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator vs push applyasdf asdf
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator vs push apply
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params);
spread operator
var params = [ "hello", true, 7 ] var other = [ 1, 2, ...params ]
push apply
var params = [ "hello", true, 7 ] var other = [].push.apply([1, 2], params)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
push apply
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/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.concat
15061602.0 Ops/sec
spread operator
57336216.0 Ops/sec
push apply
51417756.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The MeasureThat.net benchmark compares the performance of three ways to concatenate arrays in JavaScript: `Array.prototype.concat`, the spread operator (`...`), and the `push.apply()` method. **Comparison Options** The benchmark tests the following options: 1. **`Array.prototype.concat`**: This is a traditional way to concatenate two or more arrays using the `concat()` method. 2. **Spread Operator (`...`)**: This is a new ES6 feature that allows you to spread the elements of an array into another array using the syntax `[ ...arr ]`. 3. **`push.apply()` method**: This method applies the `push()` method to an array, which adds one or more elements to the end of the array. **Pros and Cons** * **`Array.prototype.concat()`**: + Pros: widely supported, easy to read. + Cons: can be slower due to the creation of a new array. * **Spread Operator (`...`)**: + Pros: concise, efficient, and modern. + Cons: requires ES6 support, may not work in older browsers or environments. * **`push.apply()` method**: + Pros: can be faster than `concat()`, uses push method directly on the array. + Cons: less intuitive, can lead to errors if not used carefully. **Library and Special JS Feature** There is no library being compared in this benchmark. However, it's worth noting that some browsers may have additional features or optimizations that affect performance. **Other Considerations** When choosing between these methods, consider the following: * Code readability: `concat()` is often easier to read than using spread operators or `push.apply()`. * Performance-critical code: if you're writing high-performance code, you may want to choose a method that's optimized for speed. * Browser support: make sure to test on different browsers and environments to ensure compatibility. **Benchmark Result** The benchmark results show the following performance order: 1. Spread Operator (`...`): 57336216 executions/second 2. `push.apply()` method: 51417756 executions/second 3. `Array.prototype.concat()`: 15061602 executions/second This suggests that the spread operator is generally the fastest way to concatenate arrays in modern browsers.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (add)
Array.prototype.concat vs spread operator (fix)
Array.prototype.concat vs spread operator on large array
Array.prototype.concat vs spread operator on small array
Comments
Confirm delete:
Do you really want to delete benchmark?