Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator (fix)
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var params = [ "hello", true, 7 ];
Tests:
Array.prototype.concat
var other = [ 1, 2 ].concat(params);
spread operator
var other = [ 1, 2, ...params ]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 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
27993874.0 Ops/sec
spread operator
85154752.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is comparing two approaches to concatenate arrays in JavaScript: `Array.prototype.concat()` method and the new ES6 spread operator (`...`). The script preparation code defines an array `params` with three elements: "hello", `true`, and `7`. **Options Compared** Two options are being compared: 1. **`Array.prototype.concat()`**: This is a traditional method for concatenating arrays, which involves creating a new array object by combining the original array with another array. 2. **Spread Operator (`...`)**: This is a new syntax introduced in ES6 that allows you to create a new array by spreading elements from an existing array. **Pros and Cons** * **`Array.prototype.concat()`**: + Pros: widely supported, easy to understand for those familiar with JavaScript arrays. + Cons: can be slower than the spread operator due to its more complex implementation (creating a new array object). * **Spread Operator (`...`)**: + Pros: generally faster, more concise and readable, especially in modern browsers that support it well. + Cons: less widely supported, may not work as expected in older browsers or environments. **Library** None. This benchmark uses only built-in JavaScript functionality. **Special JS Feature/Syntax** No special features or syntax are used beyond the spread operator. **Other Alternatives** * **Array.prototype.push()**: Another common way to concatenate arrays in JavaScript, which would involve creating an array and then pushing elements onto it. * **Array.concat() with a function**: Creating a function that takes an array as input and returns a new concatenated array.
Related benchmarks:
Array.prototype.concat vs spread operator (add)
Array.prototype.concat vs spread operator test 34234
2 6Array.prototype.concat vs spread operator 2
`Array.prototype.concat` vs `spread operator`
Comments
Confirm delete:
Do you really want to delete benchmark?