Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Concat vs push(...) for large arrays (100000 up to 5000000)
(version: 1)
Comparing the various ways to append to a large array
Comparing performance of:
Spread vs Apply
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.top.tests = {control:[], concat:[], spread:[], apply: []}; window.test = (new Array(100000)).fill(null).map((e, i) => ( { "_id": "6756f95de1bf2a3657bf2262", "index": 0, "guid": "bdc23f10-a1ac-47ad-a423-1c498f5d7857", "isActive": true, "balance": "$2,288.04", "picture": "http://placehold.it/32x32", "age": i, "eyeColor": "brown", "name": "Reid Holden", "gender": "male", "company": "KAGGLE", "email": "reidholden@kaggle.com", "phone": "+1 (844) 427-3173", "address": "923 Dewitt Avenue, Macdona, Florida, 2333", "about": "Eu quis amet ipsum id occaecat reprehenderit cillum cupidatat ullamco ad duis. Lorem tempor incididunt culpa dolor labore et officia nulla aliqua et incididunt amet dolor reprehenderit. Ut voluptate est elit quis fugiat ex magna irure eiusmod esse duis sint qui. Exercitation duis duis ullamco est eiusmod sunt eiusmod velit laboris ex elit.\r\n", "registered": "2017-07-12T07:52:14 -02:00", "latitude": 49.456753, "longitude": -37.824429, "tags": [ "est", "laborum", "laborum", "incididunt", "adipisicing", "anim", "sit" ], "friends": [ { "id": 0, "name": "Gutierrez Collins" }, { "id": 1, "name": "Lisa Richardson" }, { "id": 2, "name": "Wilson Kane" } ], "greeting": "Hello, Reid Holden! You have 4 unread messages.", "favoriteFruit": "strawberry" })); window.cutoff = 50000;
Tests:
Spread
window.top.tests.spread.push(...window.test); if (window.top.tests.spread.length > window.cutoff) { window.top.tests.spread = []; console.log('reset spread'); }
Apply
window.top.tests.apply.push.apply(window.top.tests.apply, window.test); if (window.top.tests.apply.length > window.cutoff) { window.top.tests.apply = []; console.log('reset apply'); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Spread
Apply
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; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Spread
1959.8 Ops/sec
Apply
1922.1 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 3
Concat vs push(...) for large arrays 4
Concat vs push(...) vs. spread for large arrays
Concat vs push.apply vs flat for large arrays of arrays
Concat vs push.apply vs flat for larger arrays of arrays
Concat vs push(...) for large arrays (500 up to 50000)
Concat vs push(...) for large arrays (----)
Comments
Confirm delete:
Do you really want to delete benchmark?