Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator 12
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
[ 1, 2 ].concat([ "hello", true, 7 ]);
spread operator
[ ...[ 1, 2 ], ...[ "hello", true, 7 ] ]
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:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Browser/OS:
Chrome 112 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.concat
6794179.5 Ops/sec
spread operator
20755648.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 Overview** The benchmark compares two ways to concatenate arrays in JavaScript: `Array.prototype.concat` (traditional method) and the spread operator (`...`). **Options Compared** The options being compared are: 1. **Traditional Method**: Using `Array.prototype.concat()` to concatenate two arrays. 2. **Spread Operator**: Using the spread operator (`...`) to concatenate two arrays. **Pros and Cons of Each Approach** * **Traditional Method (concat())**: + Pros: Well-established, widely supported, and easy to understand for many developers. + Cons: Can be slower than the spread operator in modern JavaScript engines. * **Spread Operator (...)**: + Pros: Fast, concise, and efficient. It's a part of the modern JavaScript standard (ES6+). + Cons: May require additional knowledge or attention from developers to write correctly. **Library Usage** In this benchmark, no specific libraries are used beyond the built-in `Array` prototype and the JavaScript language itself. **Special JS Features/Syntax** The spread operator (`...`) is a relatively new feature introduced in ECMAScript 2015 (ES6). It allows for more concise array concatenation by spreading elements into a new array. This feature was widely adopted after its introduction, making it a part of modern JavaScript development workflows. **Other Considerations** This benchmark focuses on the performance difference between two common methods of array concatenation in JavaScript. By comparing these options, the goal is to provide insight into which method is faster and more efficient for developers writing JavaScript code. **Alternatives** Other alternatives for array concatenation might include: 1. Using `Array.prototype.push()` with multiple arguments. 2. Using the `reduce()` method or other functional programming techniques to concatenate arrays. 3. Employing third-party libraries or polyfills that offer optimized array concatenation methods. These alternatives may have different performance characteristics, code readability trade-offs, and developer familiarity factors compared to the traditional concat() and spread operator approaches tested in this benchmark.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (fix)
Array.prototype.concat vs spread operator real
Array.prototype.concat vs spread operator on small array
Comments
Confirm delete:
Do you really want to delete benchmark?