const params = 7;
const other = [ 1, 2 ].concat([params]);
const params = [ 1, 2]
const other = [params, 7]
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.concat | |
spread operator |
Test name | Executions per second |
---|---|
Array.prototype.concat | 8793097.0 Ops/sec |
spread operator | 31149410.0 Ops/sec |
What is being tested?
MeasureThat.net is testing the performance of two approaches for concatenating arrays in JavaScript: the traditional Array.prototype.concat()
method and the new ES6 spread operator (...
).
Options compared
The benchmark compares the performance of two options:
Array.prototype.concat()
: This method creates a new array by copying elements from the original arrays....
): This method uses the spread operator to create a new array by copying elements from the original arrays.Pros and cons of each approach
Array.prototype.concat()
:...
):Library and its purpose
In the provided benchmark definition, there is no explicit library mentioned. However, some test cases might use external libraries that are not shown in this code snippet. If a library is used, its purpose would be to make the test more robust, reliable, or relevant.
Special JS features or syntax
There are no special JavaScript features or syntax mentioned in the provided benchmark definition.
Alternative approaches
Other alternatives for concatenating arrays include:
Array.prototype.push()
: This method appends elements to an array and returns the updated length of the array.Array.concat()
with a new array: Creating a new array using Array.from()
or another method, followed by the concat()
method.These alternatives might be faster or more efficient in certain scenarios, but they may not offer the same performance benefits as the spread operator in modern JavaScript engines.
Benchmark preparation code
The benchmark definition does not provide any script preparation code. This suggests that the test cases are already simplified and designed to focus on the performance comparison between the two approaches.
Keep in mind that benchmarking can be complex, and the results might depend on various factors such as the specific use case, browser version, platform, and hardware configuration.