Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator 2022
(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 ]; var other = [ 1, 2 ].concat(params);
spread operator
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
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
gemma2:9b
, generated one year ago):
This benchmark compares the performance of two methods for combining arrays in JavaScript: **1. `Array.prototype.concat()`:** This is the traditional method using the built-in `concat()` function on arrays. * **Benchmark Definition:** `[ 1, 2 ].concat(params);` * **Pros:** Well-established and widely understood. * **Cons:** Can be slower than the spread operator, especially for large arrays. Creates a new array copy. **2. Spread Operator (`...`)**: Introduced in ES6 (ECMAScript 2015), this uses the three dots to expand the elements of an array into another array. * **Benchmark Definition:** `[ 1, 2, ...params ]` * **Pros:** Concise syntax, often faster than `concat()`, especially for large arrays. * **Cons:** Requires knowledge of ES6 syntax. **Consideration:** The benchmark focuses on raw execution speed (executions per second). In real-world applications, consider factors like memory usage and code readability as well. **Alternatives:** * **`Array.prototype.push()`**: While not directly compared here, `push()` can be used to append elements to an array. This might be more efficient if you're repeatedly adding elements to the end of an array. * **Libraries:** Certain libraries like Lodash or Ramda provide optimized functions for array manipulation, which could potentially outperform both `concat()` and the spread operator in specific scenarios. Let me know if you have any other benchmarks you'd like analyzed!
Related benchmarks:
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 on large array
Array.prototype.concat vs spread operator on small array
Comments
Confirm delete:
Do you really want to delete benchmark?