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 = [ 1, 2, params ];
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Array.prototype.concat | |
spread operator | |
spread 2 |
Test name | Executions per second |
---|---|
Array.prototype.concat | 13371355.0 Ops/sec |
spread operator | 25865824.0 Ops/sec |
spread 2 | 47403604.0 Ops/sec |
Let's break down the benchmark and its components.
Benchmark Definition
The benchmark is designed to compare three different approaches for concatenating arrays in JavaScript:
Array.prototype.concat()
...
)[ ...array, ...other]
)Options Compared
The benchmark compares these three approaches on different test cases:
Array.prototype.concat()
with an array containing strings, booleans, and numbers....
) without any prefix or suffix.Pros and Cons
Here's a brief summary of the pros and cons of each approach:
Array.prototype.concat()
...
)[ ...array, ...other]
)concat()
and the spread operator.Library Usage
There is no explicit library usage in this benchmark. However, it's worth noting that modern JavaScript engines are optimized for ES6 features, including the spread operator.
Special JS Feature or Syntax
The benchmark uses a special syntax feature: the new ES6 spread operator (...
). This was introduced in ECMAScript 2015 (ES6) and has become widely supported by modern browsers and engines.