<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
var params = [ "hello", true, 7 ];
var result = [ 1, 2 ].concat(params);
var result = [ 1, 2, params ]
var result = _.concat([ 1, 2 ], params);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.concat | |
spread operator | |
lodash concat |
Test name | Executions per second |
---|---|
Array.prototype.concat | 8634934.0 Ops/sec |
spread operator | 29073968.0 Ops/sec |
lodash concat | 3613166.5 Ops/sec |
Let's break down the provided JSON and benchmark information.
What is being tested?
The website, MeasureThat.net, is testing three different approaches to concatenate an array with another array:
[...array]
).Options comparison
The three approaches are being compared to determine their performance differences when concatenating an array with another array using a variable source (in this case, params
) and a constant source (in this case, [1, 2]
).
Pros and cons of each approach:
Library usage
In this benchmark, the _concat function from the Lodash library is being tested. The Lodash library provides a collection of utility functions that can simplify common programming tasks, such as array manipulation. In this case, _concat
is used to concatenate two arrays in a fast and efficient manner.
Special JS feature or syntax
The benchmark uses ES6 spread operator syntax ([...params]
) to test its performance. This syntax was introduced in ECMAScript 2015 (ES6) as a new way of spreading the elements of an array into a new array.
Now, let's look at some alternatives:
Array.prototype.push()
or Array.prototype.concat()
with an initial array.