Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for loop vs concat vs push(...) vs push.apply for large arrays
(version: 1)
Comparing the various ways to append to a large array
Comparing performance of:
Control (for push) vs Concat vs Spread vs Push.apply
Created:
one year ago
by:
Guest
Jump to the latest result
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
Array.prototype.push.apply(window.top.tests.pushApply, window.test); if (window.top.tests.pushApply.length > window.cutoff) { window.top.tests.pushApply = []; console.log('reset pushApply'); }
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
Push.apply
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Control (for push)
981710.2 Ops/sec
Concat
1382396.9 Ops/sec
Spread
4240545.5 Ops/sec
Push.apply
4192860.0 Ops/sec
Related benchmarks:
Concat vs push(...) for large arrays
Concat vs push(...) vs spread for large arrays
Concat vs push(...) for large arrays using spread in test 2
gmoney - Concat vs push(...) for large arrays
Concat vs push(...) vs push.apply for large arrays
Concat vs push(...) for large arrays with PrototypePushApply
FD Concat vs push(...) for large arrays
Concat vs push vs spread for large arrays 2
Concat vs push(...) for large arrays 222
Comments
Confirm delete:
Do you really want to delete benchmark?