Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs spread js
(version: 0)
Comparing performance of:
lodash merge vs spread
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function deepMergeWithSpread(obj1, obj2) { const result = { ...obj1 }; for (let key in obj2) { if (obj2.hasOwnProperty(key)) { if (obj2[key] instanceof Object && obj1[key] instanceof Object) { result[key] = deepMergeWithSpread(obj1[key], obj2[key]); } else { result[key] = obj2[key]; } } } return result; }
Tests:
lodash merge
var a = { "_id": "66fbb8cedd880f8726d3430d", "index": 0, "guid": "0a9b7fd8-2e1c-423e-9129-a4b34edd6ea0", "isActive": false, "balance": "$3,498.70", "picture": "http://placehold.it/32x32", "age": 31, "eyeColor": "blue", "name": "Estrada Mcfarland", "gender": "male", "company": "BULLZONE", "email": "estradamcfarland@bullzone.com", "phone": "+1 (875) 565-3286", "address": "344 Oakland Place, Caledonia, Ohio, 8843", "about": "Cupidatat velit minim Lorem quis non. Ullamco magna qui commodo aliquip cillum anim ea aliqua. Tempor ullamco nulla cillum mollit veniam tempor ipsum ipsum culpa ipsum. Quis sit velit minim ad eiusmod veniam aliquip non anim veniam anim enim est cupidatat. Pariatur ipsum ipsum commodo irure laborum qui velit do est ullamco. Tempor velit ullamco Lorem non laboris culpa ullamco excepteur aliquip laboris cillum occaecat adipisicing anim.\r\n", "registered": "2014-01-31T12:10:19 -07:00", "latitude": 37.048423, "longitude": 131.714333, "tags": [ "reprehenderit", "ea", "esse", "ipsum", "Lorem", "dolor", "non" ], "friends": [ { "id": 0, "name": "Bender Battle" }, { "id": 1, "name": "Flowers Huff" }, { "id": 2, "name": "Amanda Armstrong" }]}; var b = { "_id": "66fbb8fb871c6f25070b297b", "index": 0, "guid": "65f9bf15-96b5-4e1c-8d17-a7b9f9f52cf3", "isActive": false, "balance": "$2,098.99", "picture": "http://placehold.it/32x32", "age": 39, "eyeColor": "blue", "name": "Cherry Hendrix", "gender": "female", "company": "MAGNINA", "email": "cherryhendrix@magnina.com", "phone": "+1 (842) 469-3783", "address": "645 Myrtle Avenue, Sharon, Nevada, 4405", "about": "Consequat Lorem Lorem quis ea mollit Lorem deserunt eiusmod elit. Eu est duis in incididunt exercitation consequat duis sint quis adipisicing nisi. Quis sunt excepteur laborum cillum cillum ea ullamco tempor duis esse eiusmod laboris. Velit aliquip consequat ullamco laboris laboris sit cillum commodo fugiat labore sint cillum consequat.\r\n", "registered": "2023-06-02T08:28:00 -07:00", "latitude": -67.322848, "longitude": 19.323204, "tags": [ "amet", "laboris", "cillum", "irure", "velit", "officia", "in" ], "friends": [ { "id": 0, "name": "Shanna Shelton" }, { "id": 1, "name": "Lucile Kelley" }, { "id": 2, "name": "Walker Hall" } ], "greeting": "Hello, Cherry Hendrix! You have 3 unread messages.", "favoriteFruit": "apple" }; var c = _.merge(a, b);
spread
var a = { "_id": "66fbb8cedd880f8726d3430d", "index": 0, "guid": "0a9b7fd8-2e1c-423e-9129-a4b34edd6ea0", "isActive": false, "balance": "$3,498.70", "picture": "http://placehold.it/32x32", "age": 31, "eyeColor": "blue", "name": "Estrada Mcfarland", "gender": "male", "company": "BULLZONE", "email": "estradamcfarland@bullzone.com", "phone": "+1 (875) 565-3286", "address": "344 Oakland Place, Caledonia, Ohio, 8843", "about": "Cupidatat velit minim Lorem quis non. Ullamco magna qui commodo aliquip cillum anim ea aliqua. Tempor ullamco nulla cillum mollit veniam tempor ipsum ipsum culpa ipsum. Quis sit velit minim ad eiusmod veniam aliquip non anim veniam anim enim est cupidatat. Pariatur ipsum ipsum commodo irure laborum qui velit do est ullamco. Tempor velit ullamco Lorem non laboris culpa ullamco excepteur aliquip laboris cillum occaecat adipisicing anim.\r\n", "registered": "2014-01-31T12:10:19 -07:00", "latitude": 37.048423, "longitude": 131.714333, "tags": [ "reprehenderit", "ea", "esse", "ipsum", "Lorem", "dolor", "non" ], "friends": [ { "id": 0, "name": "Bender Battle" }, { "id": 1, "name": "Flowers Huff" }, { "id": 2, "name": "Amanda Armstrong" }]}; var b = { "_id": "66fbb8fb871c6f25070b297b", "index": 0, "guid": "65f9bf15-96b5-4e1c-8d17-a7b9f9f52cf3", "isActive": false, "balance": "$2,098.99", "picture": "http://placehold.it/32x32", "age": 39, "eyeColor": "blue", "name": "Cherry Hendrix", "gender": "female", "company": "MAGNINA", "email": "cherryhendrix@magnina.com", "phone": "+1 (842) 469-3783", "address": "645 Myrtle Avenue, Sharon, Nevada, 4405", "about": "Consequat Lorem Lorem quis ea mollit Lorem deserunt eiusmod elit. Eu est duis in incididunt exercitation consequat duis sint quis adipisicing nisi. Quis sunt excepteur laborum cillum cillum ea ullamco tempor duis esse eiusmod laboris. Velit aliquip consequat ullamco laboris laboris sit cillum commodo fugiat labore sint cillum consequat.\r\n", "registered": "2023-06-02T08:28:00 -07:00", "latitude": -67.322848, "longitude": 19.323204, "tags": [ "amet", "laboris", "cillum", "irure", "velit", "officia", "in" ], "friends": [ { "id": 0, "name": "Shanna Shelton" }, { "id": 1, "name": "Lucile Kelley" }, { "id": 2, "name": "Walker Hall" } ], "greeting": "Hello, Cherry Hendrix! You have 3 unread messages.", "favoriteFruit": "apple" }; var c = deepMergeWithSpread(a,b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash merge
spread
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/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
308956.2 Ops/sec
spread
145652.0 Ops/sec
Related benchmarks:
lodash merge vs object.assign vs spread new obj
lodash merge vs object.assign vs spread (no intermediate vars)
lodash assign vs object.assign vs spread operator - variable and constant
lodash merge vs test merge
Deep merge: lodash vs ramda vs Object spread
Comments
Confirm delete:
Do you really want to delete benchmark?