Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread operator with no damn jq
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator
Created:
5 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 ways to combine arrays in JavaScript: **1. `Array.prototype.concat()`:** This is the traditional method, using the built-in `concat` function on an array object. ```javascript var params = ["hello", true, 7]; var other = [1, 2].concat(params); ``` **2. Spread Operator (`...`)**: This is a newer method introduced in ES6 (ECMAScript 2015), using the three dots (`...`) to expand an array's contents into another array. ```javascript var params = ["hello", true, 7]; var other = [1, 2, ...params]; ``` **Pros and Cons:** * **`concat()`**: * **Familiar:** Has been around longer, so many developers are comfortable with it. * **Can work with non-array arguments:** `concat()` can accept individual elements as arguments, not just arrays. * **Potentially less efficient**: Older method, might have performance overhead compared to the spread operator in some scenarios. * **Spread Operator (`...`)**: * **Concise and readable:** Makes code more compact and easier to understand. * **Often faster:** Generally considered more performant than `concat()` for similar operations. **Other Considerations:** * **Impact on Memory:** Both methods create new arrays, so memory usage needs to be considered if you're dealing with very large arrays. * **Alternatives:** Depending on your specific need, other options might exist: * Array Methods (like `push`, `unshift`): For modifying existing arrays in-place rather than creating new ones. **Benchmark Results Interpretation:** The provided results show that the "spread operator" is significantly faster in this particular case, executing over four times as many operations per second compared to `concat()`. This reinforces the general perception of the spread operator's efficiency. Let me know if you have any more questions!
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?