concat vs spread performance

Benchmark created on


Description

Benchmarks comparing Array.prototype.concat with array spreading. Benchmark code comes from this excellent StackOverflow post: https://stackoverflow.com/a/48866316

Setup

let big = (new Array(1e5)).fill(99);
let i, x;

let a = (new Array(1e3)).fill(99);
let b = (new Array(1e3)).fill(99);
let c = (new Array(1e3)).fill(99);
let d = (new Array(1e3)).fill(99);

Test runner

Ready to run.

Testing in
TestOps/sec
Concat (big)
for(i = 0; i < 1e2; i++) x = [].concat(big)
ready
Spread (big)
for(i = 0; i < 1e2; i++) x = [...big]
ready
Concat (many)
for(i = 0; i < 1e2; i++) x = [1,2,3].concat(a, b, c, d)
ready
Spread (many)
for(i = 0; i < 1e2; i++) x = [1,2,3, ...a, ...b, ...c, ...d]
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.