Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Concat vs push(...) vs spread
Comparing the various ways to append to an array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser:
Chrome 123
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Concat
4360948.5 Ops/sec
Push spread
869511.6 Ops/sec
Spread 2
2877261.5 Ops/sec
Push
186723.6 Ops/sec
Script Preparation code:
var test1 = (new Array(50)).fill(0).map((d, i) => Math.random().toString()); var test2 = (new Array(50)).fill(0).map((d, i) => Math.random().toString());
Tests:
Concat
var both = test1.concat(test2); both[0] = both[50];
Push spread
var both = [].push(...test1, ...test2); both[0] = both[50];
Spread 2
var both = [...test1, ...test2]; both[0] = both[50];
Push
var len1 = test1.length; var len2 = test2.length; var both = new Array(len1 + len2); for (var i = 0; i < len1; ++i) both[i] = test1[i]; for (var i = 0; i < len2; ++i) both[i + len1] = test2[i]; both[0] = both[50];