Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
spread vs concat xxx2
(version: 0)
Comparing performance of:
concat vs spread
Created:
8 years ago
by:
Guest
Jump to the latest result
Tests:
concat
var params = [ "hello", true, 7 ]; var other = [ 1, 2 ].concat(params);
spread
var params = [ "hello", true, 7 ] var other = [ 1, 2, ...params ]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
concat
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
gemma2:9b
, generated one year ago):
This benchmark tests the performance of two different methods for combining arrays in JavaScript: `concat()` and the spread operator (`...`). **Here's a breakdown:** * **`concat()`** : This is a built-in JavaScript method that takes one or more arrays as arguments and returns a new array containing the elements of all input arrays. * **Spread Operator (`...`)**: Introduced in ES6, the spread operator allows you to expand the contents of an iterable (like an array) into individual elements. **Test Cases:** * Both test cases create a small array `params` with three elements: "hello", true, and 7. * The `"concat"` case uses `concat()` to join the arrays [1, 2] and `params`. * The `"spread"` case uses the spread operator to include all elements of `params` within a new array containing [1, 2]. **Pros/Cons:** * **`concat()`**: * **Pros:** Widely supported in older browsers. More readable for some developers. * **Cons:** Can be slower than the spread operator for larger arrays because it creates a new array on every call. * **Spread Operator (`...`)**: * **Pros:** Generally faster for large arrays, as it avoids creating unnecessary intermediate arrays. Concise and expressive syntax. * **Cons:** Requires understanding of ES6 syntax and might not be supported in older browsers (although this is increasingly rare). **Other Considerations:** * **Array Size:** The performance difference between `concat()` and the spread operator becomes more significant with larger arrays. **Alternatives:** While less common, you could explore using array methods like `push` or `unshift` to build a new array. However, these methods tend to be slower for joining multiple arrays compared to both `concat()` and the spread operator. **Key Takeaway:** For most scenarios involving combining arrays, the spread operator (`...`) is generally more efficient than `concat()`, especially when dealing with larger datasets.
Related benchmarks:
Array.prototype.concat vs Spread operator
Array.prototype.concat vs Spread operator
concat 2 arrays: Array.prototype.concat vs spread operator
ES6 Array concat vs spread operator
Array.prototype.concat vs spread operator 12
Comments
Confirm delete:
Do you really want to delete benchmark?