Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Concat vs double spread vs array push
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Array.prototype.concat vs spread operator vs Push
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var arr1 = Array(50).fill(1) var arr2 = Array(100).fill("2") var x = arr1.concat(arr2);
spread operator
var arr1 = Array(50).fill(1) var arr2 = Array(100).fill("2") var x = [ ...arr1, ...arr2 ]
Push
var arr1 = Array(50).fill(1) var arr2 = Array(100).fill("2") var x = arr1.push(...arr2);
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
Push
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):
**Benchmark Overview** The MeasureThat.net benchmark measures the performance of three different approaches to concatenate arrays in JavaScript: `concat()`, spread operator (`...`), and `push()`. **Approach 1: Concat() Method** The `concat()` method is a traditional way to combine two or more arrays. It creates a new array by copying all elements from the source arrays. Pros: * Well-supported across most browsers * Easy to read and understand Cons: * Creates a new array, which can lead to performance overhead for large datasets * May not be as efficient as other methods in some cases **Approach 2: Spread Operator (`...`)** The spread operator is a new feature introduced in ES6 that allows you to expand an array or object into a new iterable. Pros: * More concise and expressive than the `concat()` method * Can lead to better performance due to fewer function calls Cons: * Requires JavaScript version 5.0+ to work (and may be disabled in older browsers) * May not be as widely supported as other methods **Approach 3: Push() Method** The `push()` method adds one or more elements to the end of an array and returns the new length of the array. Pros: * Can lead to better performance due to fewer function calls * Works with modern JavaScript engines Cons: * May not be as readable or intuitive as other methods * Requires careful handling of edge cases, such as inserting at a specific index **Library Usage** None of the benchmark tests explicitly use any external libraries. **Special JS Features/Syntax** The spread operator (`...`) is a new feature introduced in ES6. It requires JavaScript version 5.0+ to work (and may be disabled in older browsers). The `concat()` method and `push()` method do not require any special syntax. **Other Alternatives** If you need to concatenate arrays, other alternatives might include: * Using the `Array.prototype.reduce()` method * Creating a new array using an array constructor (e.g., `[...arr1].concat(arr2)`) * Using a library like Lodash (which provides a `concat` function) Keep in mind that performance differences between these methods may vary depending on the specific use case and JavaScript engine used.
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?