Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
concat 2 arrays: Array.prototype.concat vs spread operator
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [ 1, 2, 3 ]; var b = [ 4, 5, 6 ];
Tests:
Array.prototype.concat
var result = a.concat(b);
spread operator
var result = [ ...a, ...b ];
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:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0
Browser/OS:
Chrome 141 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
25058402.0 Ops/sec
spread operator
42029056.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is tested?** The benchmark tests two approaches for concatenating two arrays: `Array.prototype.concat` and the spread operator (`[ ...a, ...b ]`). The goal is to compare their performance in JavaScript microbenchmarks. **Options compared** Two options are being compared: 1. **`Array.prototype.concat`**: A traditional method for concatenating arrays, which was part of the ECMAScript standard before the introduction of the spread operator. 2. **Spread operator (`[ ...a, ...b ]`)**: A new syntax introduced in ECMAScript 2015 (ES6) that allows creating a new array by spreading elements from existing arrays. **Pros and cons of each approach** 1. `Array.prototype.concat`: * Pros: + Widely supported and well-established. + Can be used with older browsers or environments that don't support the spread operator. * Cons: + May have performance overhead due to the function call and array creation. 2. Spread operator (`[ ...a, ...b ]`): * Pros: + More concise and expressive syntax. + Can be faster than `concat` because it avoids the function call overhead. * Cons: + Requires ECMAScript 2015 support (ES6+) for older browsers or environments. **Library usage** In this benchmark, there is no explicit library usage mentioned. However, the spread operator syntax relies on the `Array.prototype` object and the `...` spread syntax, which are built-in JavaScript features. **Special JS feature/syntax** The spread operator (`[ ...a, ...b ]`) uses a new syntax introduced in ECMAScript 2015 (ES6). This syntax is not mentioned in older browsers or environments that don't support ES6+.
Related benchmarks:
Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator!!!
Concat vs Spread (Two Arrays)
Array.prototype.concat vs spread operator (new try)
Comments
Confirm delete:
Do you really want to delete benchmark?