Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Concat vs push(...) vs push.apply for large 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 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Spread
453K/s
Push.apply
304K/s
Control (for push)
115K/s
Concat
104K/s
View exact numbers
Test name
Executions per second
✓
Spread
452,559 Ops/sec
Push.apply
303,714 Ops/sec
Control (for push)
114,617 Ops/sec
Concat
104,379 Ops/sec
Script Preparation code:
window.top.tests = {control:[], concat:[], spread:[], pushapply:[]}; window.test = (new Array(10)).fill(null); window.cutoff = 5000;
Tests:
Control (for push)
for (let element of window.test) window.top.tests.control.push(element); if (window.top.tests.control.length > window.cutoff) { window.top.tests.control = []; console.log('reset control'); }
Concat
window.top.tests.concat = window.top.tests.concat.concat(window.test); if (window.top.tests.concat.length > window.cutoff) { window.top.tests.concat = []; console.log('reset concat'); }
Spread
window.top.tests.spread.push(...window.test); if (window.top.tests.spread.length > window.cutoff) { window.top.tests.spread = []; console.log('reset spread'); }
Push.apply
window.top.tests.pushapply.push.apply(window.top.tests.pushapply, window.test); if (window.top.tests.spread.length > window.cutoff) { window.top.tests.pushapply = []; console.log('reset pushapply'); }