Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator vs push spreaad operator
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push spread operator
Comparing performance of:
Array.prototype.concat vs spread operator vs spear push
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 ]
spear push
var params = [ "hello", true, 7 ] var other = [ 1, 2].push(...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
spear push
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/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 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
16373690.0 Ops/sec
spread operator
58520080.0 Ops/sec
spear push
66715168.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. **What's being tested:** The benchmark is comparing three approaches for concatenating arrays in JavaScript: 1. `Array.prototype.concat()` 2. The spread operator (`...`) 3. `push` with spread operator (`...`) These three approaches are compared to determine which one is the most efficient. **Options compared:** * **Traditional approach:** `Array.prototype.concat()`, which takes an array and another array as arguments and returns a new array containing all elements from both arrays. * **Spread operator approach:** Using the spread operator (`...`) to concatenate two arrays. This creates a new array with elements from both arrays. * **Push with spread operator approach:** Using `push` method in combination with the spread operator (`...`) to concatenate an array. **Pros and Cons:** * **Traditional approach (concat())**: Pros: + Well-established and widely supported. + Easy to understand for developers familiar with this method. Cons: + Creates a new array, which can lead to performance issues if arrays are large. * **Spread operator approach:** Pros: + More efficient than traditional approach (concat()) since it doesn't create a new array. + Modern and widely adopted syntax. Cons: + May require more effort for developers who aren't familiar with this syntax. * **Push with spread operator approach:** Pros: + Similar performance to the spread operator approach. + Allows for more flexibility in concatenation (e.g., adding elements at different indices). Cons: + Requires support for `push` method and spread operator (`...`) in older browsers. **Library usage:** None of the tested approaches require any libraries. **Special JS features or syntax:** The benchmark uses the spread operator (`...`) and `push` with spread operator (`...`), which are modern JavaScript features. The traditional approach (`Array.prototype.concat()`) is a well-established method, but it may not be as efficient as the other two approaches.
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 large array
Array.prototype.concat vs spread operator on small array
Comments
Confirm delete:
Do you really want to delete benchmark?