Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator with bigger arrays
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
var params = [ "hello", true, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9 ]; var other = [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 ].concat(params);
spread operator
var params = [ "hello", true, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9 ]; var other = [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, ...params ]
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:
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 break down the provided benchmark and its options. **Benchmark Definition** The test compares two methods for concatenating arrays: 1. `Array.prototype.concat()` 2. The new ES6 spread operator (`...`) **Options Compared** * `Array.prototype.concat()`: This method uses the `concat()` function to concatenate two or more arrays. + Pros: Widely supported, well-documented, and has been around for a long time. + Cons: Can be slower than the spread operator, especially for large arrays. * The new ES6 spread operator (`...`): This operator is used to create a new array by spreading elements from an existing array or other iterable. + Pros: Generally faster than `concat()`, more concise, and can improve code readability. + Cons: Requires modern browsers that support ES6 features. **Other Considerations** * The test uses two large arrays with 50 elements each to simulate a real-world scenario where concatenation might occur. This helps to ensure the results are accurate and representative of typical use cases. * The benchmark is run on Chrome 95 on Windows, which is a relatively modern browser that supports ES6 features. **Library Used** None in this case, as both methods are part of the built-in JavaScript API. **Special JS Feature/ Syntax** The spread operator (`...`) is a new feature introduced in ECMAScript 2015 (ES6). It allows for concise array creation and has been adopted by most modern browsers. Now, let's look at some alternative approaches that could be considered: * Using `Array.prototype.push()`: Instead of concatenating two arrays, you can push elements from one array into another using `push()`. This approach is generally faster but might not be as concise or readable. * Using `Array.prototype.reduce()`: Another option for concatenation is to use `reduce()` with a custom accumulator function. However, this approach can be more complex and may not be as performant. These alternatives could be considered if you want to explore different approaches to array concatenation in JavaScript.
Related benchmarks:
Array.prototype.concat vs Spread operator
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (fix)
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?