Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Concat vs push.apply vs flat for large arrays of arrays
(version: 1)
Comparing the various ways to append to a large array again
Comparing performance of:
Control (for push) vs Concat vs Spread vs Flat
Created:
one year ago
by:
Guest
Jump to the latest result
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.apply(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'); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Control (for push)
Concat
Spread
Flat
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Control (for push)
635802.3 Ops/sec
Concat
287368.5 Ops/sec
Spread
298332.1 Ops/sec
Flat
262328.7 Ops/sec
Related benchmarks:
Concat vs push(...) for large arrays of arrays
Concat vs push(...) vs flat for large arrays of arrays
Concat vs push(...) for large arrays 2
Concat vs push(...) for large arrays 3
Concat vs push(...) for large arrays 4
Concat vs push(...) vs. spread for large arrays
apply vs spread
Concat vs push vs spread for large arrays 2
Push-spread vs concat assignment
Comments
Confirm delete:
Do you really want to delete benchmark?