Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Concat vs push(...) vs flat for large arrays of arrays
Comparing the various ways to append to a large array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 14_8_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 14
Operating system:
iOS 14.8.1
Device Platform:
Mobile
Date tested:
4 months ago
Flat
1.0M/s
Concat
576K/s
Control (for push)
478K/s
Spread
370K/s
View exact numbers
Test name
Executions per second
✓
Flat
1,000,634 Ops/sec
Concat
576,090 Ops/sec
Control (for push)
478,383 Ops/sec
Spread
370,294 Ops/sec
Script Preparation code:
window.top.tests = {control:[], concat:[], spread:[], flat: []}; window.test = (new Array(10)).fill(null); window.arrays = (new Array(10)).fill(window.test); window.cutoff = 5000;
Tests:
Control (for push)
window.top.tests.control = window.arrays.reduce((acc, arr) => { acc.push(...arr); return acc; }, []); if (window.top.tests.control.length > window.cutoff) { window.top.tests.control = []; console.log('reset control'); }
Concat
window.top.tests.concat = window.arrays.reduce((acc, arr) => acc.concat(arr), []); if (window.top.tests.concat.length > window.cutoff) { window.top.tests.concat = []; console.log('reset concat'); }
Spread
window.top.tests.spread = window.arrays.reduce((acc, arr) => [...acc, ...arr], []); if (window.top.tests.spread.length > window.cutoff) { window.top.tests.spread = []; console.log('reset spread'); }
Flat
window.top.tests.flat = window.arrays.flat(); if (window.top.tests.flat.length > window.cutoff) { window.top.tests.flat = []; console.log('reset flat'); }