Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs object.assign vs spread with larger data and no mutation
(version: 0)
Comparing performance of:
lodash merge vs object.assign vs spread
Created:
4 years 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>
Tests:
lodash merge
var a = { "_id": "624863161dde7aa8538857e6", "index": 0, "guid": "4be322b0-459c-41aa-bd09-f3227cd353df", "isActive": false, "balance": "$3,816.12", "picture": "http://placehold.it/32x32", "age": 26, "eyeColor": "brown", "name": "Caitlin Beach", "gender": "female", "company": "MICROLUXE", "email": "caitlinbeach@microluxe.com", "phone": "+1 (954) 462-3548", "address": "854 Sapphire Street, Biddle, Colorado, 1002", "about": "Adipisicing proident labore qui est minim tempor. Ipsum est cillum nisi exercitation laboris irure. Enim tempor elit quis est deserunt cupidatat dolore. Mollit aliquip enim proident non commodo non sunt tempor nisi elit. Deserunt ex proident mollit esse. Ea Lorem sit ipsum occaecat ad ullamco.\r\n", "registered": "2018-03-22T05:20:17 +07:00", "latitude": 69.438455, "longitude": 113.552142 }; var b = { "eyeColor": "bdrown", "name": "Caitlind Beach", "gender": "femalde", "company": "MICRdOLUXE", "email": "caitlindbeach@microluxe.com", "phone": "+1 (954)d 462-3548", }; var c = _.merge(a, b);
object.assign
var a = { "_id": "624863161dde7aa8538857e6", "index": 0, "guid": "4be322b0-459c-41aa-bd09-f3227cd353df", "isActive": false, "balance": "$3,816.12", "picture": "http://placehold.it/32x32", "age": 26, "eyeColor": "brown", "name": "Caitlin Beach", "gender": "female", "company": "MICROLUXE", "email": "caitlinbeach@microluxe.com", "phone": "+1 (954) 462-3548", "address": "854 Sapphire Street, Biddle, Colorado, 1002", "about": "Adipisicing proident labore qui est minim tempor. Ipsum est cillum nisi exercitation laboris irure. Enim tempor elit quis est deserunt cupidatat dolore. Mollit aliquip enim proident non commodo non sunt tempor nisi elit. Deserunt ex proident mollit esse. Ea Lorem sit ipsum occaecat ad ullamco.\r\n", "registered": "2018-03-22T05:20:17 +07:00", "latitude": 69.438455, "longitude": 113.552142 }; var b = { "eyeColor": "bdrown", "name": "Caitlind Beach", "gender": "femalde", "company": "MICRdOLUXE", "email": "caitlindbeach@microluxe.com", "phone": "+1 (954)d 462-3548", }; var c = Object.assign({}, a, b);
spread
var a = { "_id": "624863161dde7aa8538857e6", "index": 0, "guid": "4be322b0-459c-41aa-bd09-f3227cd353df", "isActive": false, "balance": "$3,816.12", "picture": "http://placehold.it/32x32", "age": 26, "eyeColor": "brown", "name": "Caitlin Beach", "gender": "female", "company": "MICROLUXE", "email": "caitlinbeach@microluxe.com", "phone": "+1 (954) 462-3548", "address": "854 Sapphire Street, Biddle, Colorado, 1002", "about": "Adipisicing proident labore qui est minim tempor. Ipsum est cillum nisi exercitation laboris irure. Enim tempor elit quis est deserunt cupidatat dolore. Mollit aliquip enim proident non commodo non sunt tempor nisi elit. Deserunt ex proident mollit esse. Ea Lorem sit ipsum occaecat ad ullamco.\r\n", "registered": "2018-03-22T05:20:17 +07:00", "latitude": 69.438455, "longitude": 113.552142 }; var b = { "eyeColor": "bdrown", "name": "Caitlind Beach", "gender": "femalde", "company": "MICRdOLUXE", "email": "caitlindbeach@microluxe.com", "phone": "+1 (954)d 462-3548", }; var c = { ...a, ...b };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash merge
object.assign
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark measures the performance of three different methods to merge two objects in JavaScript: 1. `_.merge` (Lodash library) 2. `Object.assign` 3. `Spread Operator` (`{...a, ...b}`) **Options Compared** Each test case compares the execution time of a single run of each method. **Methods Breakdown** 1. **`.merge` (Lodash)**: Uses the `lodash.merge` function to merge two objects. 2. **`Object.assign`**: Uses the `Object.assign()` method to create a new object and copy properties from the first object into it, then copies properties from the second object into the resulting object. 3. **`Spread Operator`**: Uses the spread operator (`{...a, ...b}`) to merge two objects. **Performance Results** The latest benchmark results show that: * `spread` is the fastest method with an average execution time of 818,108,830 executions per second (Chrome 100). * `_.merge` is slower than `spread`, but faster than `Object.assign`. Its average execution time is 170,918,330 executions per second. * `Object.assign` is the slowest method, with an average execution time of 160,176,070 executions per second. **Conclusion** The spread operator appears to be the most efficient way to merge two objects in JavaScript, followed closely by Lodash's `.merge` function. The `Object.assign` method is slower due to its overhead and the need to create a new object for each copy operation.
Related benchmarks:
lodash merge vs object.assign vs spread new obj
lodash.assign vs object.assign vs spread
Array Properties Merge: Lodash merge vs Object.assign
lodash merge vs object.assign vs spread (no intermediate vars)
lodash assign vs object.assign vs spread operator - variable and constant
Comments
Confirm delete:
Do you really want to delete benchmark?