var params = new Array(90000);
var other = [ 1, 2 ].concat(params);
var params = new Array(90000);
var other = [ 1, 2, params ]
var params = new Array(90000);
var other = [ 1, 2 ].push(params);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.concat | |
spread operator | |
Push |
Test name | Executions per second |
---|---|
Array.prototype.concat | 7329.1 Ops/sec |
spread operator | 2195.3 Ops/sec |
Push | 1298.0 Ops/sec |
Let's break down the benchmark and its test cases.
Benchmark Purpose
The goal of this benchmark is to compare the performance of three different methods for concatenating arrays: Array.prototype.concat()
, the new ES6 spread operator (...
), and the push()
method with multiple arguments.
Options Compared
params
) and then appending the other
array....
operator to spread the elements of the params
array into the other
array, effectively concatenating them.push()
on the other
array multiple times, passing each element from the params
array as an argument.Pros and Cons
concat()
.push()
.Library Usage
None of the test cases use external libraries.
Special JS Features/Syntax
The benchmark uses ES6 syntax (the spread operator) and JavaScript's new
keyword for creating arrays.
Other Considerations
params
) with 90,000 elements. The performance of each method may be affected by memory allocation and deallocation.Alternatives
If you want to compare performance with alternative methods, you could consider:
slice()
instead of concat()
.for
loop.Keep in mind that each alternative would require modifying the benchmark code and test cases to accommodate the new scenarios.