var params = [ "hello", true, 7 ];
var other = [ 1, 2 ].concat(params);
var other = [ 1, 2, params ]
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.concat | |
spread operator |
Test name | Executions per second |
---|---|
Array.prototype.concat | 7246468.0 Ops/sec |
spread operator | 9113388.0 Ops/sec |
Let's break down the benchmark and explain what's being tested.
Benchmark Definition
The benchmark is comparing two approaches to concatenate arrays in JavaScript: Array.prototype.concat()
method and the new ES6 spread operator (...
). The script preparation code defines an array params
with three elements: "hello", true
, and 7
.
Options Compared
Two options are being compared:
Array.prototype.concat()
: This is a traditional method for concatenating arrays, which involves creating a new array object by combining the original array with another array....
): This is a new syntax introduced in ES6 that allows you to create a new array by spreading elements from an existing array.Pros and Cons
Array.prototype.concat()
:...
):Library
None. This benchmark uses only built-in JavaScript functionality.
Special JS Feature/Syntax
No special features or syntax are used beyond the spread operator.
Other Alternatives