Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array concat vs spread operator vs push spread vs push
(version: 1)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Array.prototype.concat vs spread operator vs Push with spread vs Push without spread
Created:
3 years ago
by:
Registered User
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 with spread
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].push(...params);
Push without spread
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].push(params[0], params[1], params[2]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
Push with spread
Push without spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** MeasureThat.net is comparing four ways to concatenate an array in JavaScript: 1. `Array.prototype.concat()` 2. The new ES6 spread operator (`...`) 3. `push()` with the spread operator (`...`) These methods are compared for their performance on various browsers and devices. **Options being compared:** The comparison focuses on the following options: * Using `concat()` to concatenate an array * Using the spread operator (`...`) to concatenate an array * Using `push()` with the spread operator (`...`) to add elements to an array **Pros and Cons of each approach:** 1. **`Array.prototype.concat()`**: This is a traditional way of concatenating arrays in JavaScript. It creates a new array and copies all elements from both arrays into it. * Pros: Well-established, easy to understand * Cons: Creates a new array, can be slower due to memory allocation 2. **Spread operator (`...`)**: This is a modern way of concatenating arrays introduced in ES6. It uses the spread syntax to concatenate an array. * Pros: More concise, faster than `concat()` (since it doesn't create a new array) * Cons: Requires knowledge of the spread operator syntax 3. **`push()` with spread operator (`...`)**: This method uses the spread operator to add elements to an existing array using the `push()` method. * Pros: More concise, faster than concatenating and then pushing (since it avoids creating a new array) * Cons: Requires knowledge of the spread operator syntax **Library usage:** None of the test cases use any libraries. **Special JS feature or syntax:** The spread operator (`...`) is used in three out of four test cases. It's a modern JavaScript feature introduced in ES6, which allows for concise array concatenation and spreading of arrays into new arrays. **Alternatives:** Other alternatives to concatenate arrays include: * Using `Array.prototype.slice()` to create a shallow copy of an array * Using `array.push(...)` to add elements to an existing array (without the spread operator) * Using `array.concat(array2)` to concatenate two arrays However, these methods may have performance implications or require additional memory allocations, making the spread operator and `push()` with spread operator potentially more efficient.
Related benchmarks:
Array.prototype.concat vs spread operator
concat 2 arrays: Array.prototype.concat vs spread operator
ES6 Array concat vs spread operator
Array concat vs spread operator vs push with more data
Array.prototype.concat vs spread operator real
Comments
Confirm delete:
Do you really want to delete benchmark?