Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.prototype.concat vs spread vs push spread
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
Array.prototype.concat vs spread operator vs push spread
Created:
3 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 ]
push spread
var params = [ "hello", true, 7 ] var other = [ 1, 2 ] other.push(...params)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array.prototype.concat
spread operator
push 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
llama3.2:3b
, generated one year ago):
**What is tested on the provided JSON?** The benchmark compares three different approaches for adding elements to an array in JavaScript: `Array.prototype.concat()`, the new ES6 spread operator (`...`), and the `push()` method with the spread operator (`...`). The benchmark tests which approach is the fastest. **Options compared:** 1. `Array.prototype.concat()`: a traditional method for concatenating arrays using the `concat()` method. 2. New ES6 spread operator (`...`): a new syntax introduced in ECMAScript 2015 (ES6) that allows spreading elements of an array into another array. 3. `push()` method with the spread operator (`...`): a combination of the `push()` method and the spread operator, which adds elements to the end of an array. **Pros and Cons:** 1. **Array.prototype.concat()**: * Pros: widely supported across browsers and JavaScript engines, easy to understand and use. * Cons: can be slower than other approaches due to the overhead of creating a new array. 2. **New ES6 spread operator (`...`)**: * Pros: concise and expressive syntax, faster execution time compared to `concat()`. * Cons: may not be supported in older browsers or JavaScript engines, requires understanding of the syntax. 3. **push()` method with the spread operator (`...`)**: * Pros: balances conciseness with support for older browsers, easy to understand and use. * Cons: slightly slower than `concat()`, but faster than using only the spread operator. **Library usage:** None of the benchmark test cases explicitly uses any JavaScript libraries or frameworks. The tests are self-contained and focus on comparing different approaches for adding elements to an array. **Special JS features or syntax:** The benchmark uses the new ES6 spread operator (`...`) which is a language feature introduced in ECMAScript 2015 (ES6). This feature allows spreading elements of an array into another array, making it concise and expressive. **Other alternatives:** Other ways to add elements to an array include: 1. `Array.prototype.push()`: adds one or more elements to the end of an array. 2. `Array.prototype.splice()`: modifies an array by replacing a range of existing elements with new content. 3. `Array.prototype.slice()`: creates a shallow copy of a portion of an array. These alternatives may have different performance characteristics and use cases compared to the approaches tested in this benchmark.
Related benchmarks:
concat 2 arrays: Array.prototype.concat vs spread operator
Array.prototype.concat vs spread operator (add)
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?