Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array concat vs spread items test
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method and push
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
Array.prototype.concat
const arr = Array.from({ length: 50 }).map((i, index) => ({id: index, name: `name for ${index}`})); const arr2 = Array.from({ length: 50 }).map((i, index) => ({id: 50 + index, name: `name for ${50 + index}`})); return arr.concat(arr2);
spread operator
const arr = Array.from({ length: 50 }).map((i, index) => ({id: index, name: `name for ${index}`})); const arr2 = Array.from({ length: 50 }).map((i, index) => ({id: 50 + index, name: `name for ${50 + index}`})); return [...arr, ...arr2];
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):
The provided JSON represents a JavaScript microbenchmarking test created on MeasureThat.net. This test compares the performance of two approaches: using the traditional `concat()` method and pushing items to an array, versus using the new ES6 spread operator (`...`) to concatenate arrays. **Options being compared:** 1. **Traditional concat() method**: This approach uses the `concat()` method to combine two arrays. 2. **Spread operator**: This approach uses the `...` spread operator to concatenate two arrays. **Pros and Cons of each approach:** * Traditional concat() method: + Pros: Well-established, widely supported, and easy to understand. + Cons: Can be slower than the spread operator, especially for large arrays. * Spread operator: + Pros: More modern and efficient, reduces memory allocation, and can be faster for large arrays. + Cons: May not work correctly with older browsers or JavaScript versions that do not support it. **Library/Language features used in the test case:** * None mentioned, as this is a basic JavaScript benchmarking test. **Special JS feature or syntax used:** The spread operator (`...`) introduced in ES6 (ECMAScript 2015) allows for more concise and expressive array creation and manipulation. It's a modern feature that's widely supported in modern browsers and JavaScript engines. **Other alternatives:** In addition to the traditional concat() method and the spread operator, there are other approaches to concatenate arrays, such as: * `Array.prototype.push.apply()` (pushing all elements from one array to another) * `Array.prototype.splice()` (modifying an existing array by inserting new elements) However, these alternatives might not be as efficient or readable as the traditional concat() method and the spread operator. **Benchmark preparation code explanation:** The provided benchmark definitions create two arrays (`arr` and `arr2`) with 50 elements each. Each element is an object with an `id` and a `name`. The benchmark then concatenates these two arrays using both the traditional concat() method and the spread operator, and measures their performance. **Latest benchmark result:** The latest benchmark results show that the spread operator outperforms the traditional concat() method in terms of executions per second (e.g., 282612.5 vs. 269879.21875 for Chrome 116 on a Mac OS X 10.15.7 device).
Related benchmarks:
Array.prototype.concat vs spread operator
Array.prototype.concat vs Spread operator
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator real
Array.prototype.concat vs spread operator 12
Comments
Confirm delete:
Do you really want to delete benchmark?