var arr = Array(100).fill([{n: ''}]);
var params = [ "hello", true, 7 ];
var other = [ 1, 2 ].concat(params);
var params = [ "hello", true, 7 ]
var other = [ 1, 2, params ]
var params = [ "hello", true, 7 ];
var other = $.merge([1, 2], params);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.concat | |
spread operator | |
jQuery merge |
Test name | Executions per second |
---|---|
Array.prototype.concat | 6607075.5 Ops/sec |
spread operator | 5146072.0 Ops/sec |
jQuery merge | 1900181.5 Ops/sec |
Let's dive into the benchmark.
What is being tested?
MeasureThat.net is comparing three approaches to concatenate arrays:
concat()
function on the Array
prototype....
): A new ES6 feature that allows spreading an array's elements into a new array using the syntax new Array([...]).push(...)
or simply [...array]
.$.merge()
function from jQuery to concatenate arrays.Options comparison
The three options are being compared in terms of performance, which is typically measured as the number of executions per second (ExecutionsPerSecond).
...
): This method is generally faster because it only requires a single operation to create a new array with the spread elements.Pros and Cons
Here's a brief summary:
...
):Library usage
The $.merge()
function is part of the jQuery library. It's a utility function that allows concatenating two arrays.
Special JS feature or syntax
None mentioned in this benchmark.
Other alternatives
If you're interested in exploring other approaches, consider:
new Set()
and adding elements to it is another way to create an array-like object.