Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep merge: lodash vs ramda vs Object spread
(version: 0)
Deep merge: lodash vs ramda vs Object spread
Comparing performance of:
lodash deep merge vs ramda deep merge vs object spread deep merge
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
Tests:
lodash deep merge
const a = { a: { c: { e: { h:4 }, f: 3 }, d: 2 }, b: 1 }; const b = { a: { c: { e: { g: true } } } }; const c = _.merge(a, b)
ramda deep merge
const a = { a: { c: { e: { h:4 }, f: 3 }, d: 2 }, b: 1 }; const b = { a: { c: { e: { g: true } } } }; const c = R.mergeDeepRight(a, b);
object spread deep merge
const a = { a: { c: { e: { h:4 }, f: 3 }, d: 2 }, b: 1 }; const b = { a: { c: { e: { g: true } } } }; const c = {...a, ...b, a: { ...a.a, ...b.b, c: { ...a.a.c, ...b.a.c, e: { ...a.a.c.e, ...b.a.c.e } } } };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash deep merge
ramda deep merge
object spread deep merge
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/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash deep merge
530019.2 Ops/sec
ramda deep merge
1139689.6 Ops/sec
object spread deep merge
4576781.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Overview** The benchmark compares three approaches for performing a deep merge operation on JavaScript objects: 1. Lodash (`_.merge`) 2. Ramda (`R.mergeDeepRight`) 3. Object spread operator (`...`) **What is being tested?** The benchmark tests how fast each approach can perform a deep merge operation between two objects. The objects have nested properties, which requires the merges to be recursive. **Options compared** Here's a brief overview of each option: * **Lodash (`.merge`)**: Lodash provides a versatile utility function for merging objects. In this benchmark, it uses the `_.merge` function with the default settings. * **Ramda (`.R.mergeDeepRight`)**: Ramda is a functional programming library that offers various utility functions. In this benchmark, it uses the `R.mergeDeepRight` function, which merges two objects in a deep and recursive manner, starting from the rightmost property. * **Object spread operator (`...`)**: This is a new syntax introduced in ECMAScript 2018 (ES10). It allows you to merge two objects by spreading their properties into a new object. **Pros and Cons** Here are some pros and cons of each approach: * **Lodash (.merge)**: + Pros: Easy to use, well-documented, and widely supported. + Cons: May be slower than other approaches due to its iterative nature. * **Ramda (R.mergeDeepRight)**: + Pros: Fast, concise, and declarative. + Cons: May be less intuitive for beginners due to its functional programming style. * **Object spread operator (`...`)**: + Pros: New syntax, easy to read and write, and fast. + Cons: Requires modern browsers (ES10+) and may not work in older versions. **Libraries used** In the benchmark code, two libraries are used: 1. Lodash (`_.merge`) 2. Ramda (`R.mergeDeepRight`) These libraries offer a convenient way to perform deep merges without having to implement them manually. **Special JS features or syntax** The Object spread operator (`...`) is a new feature introduced in ECMAScript 2018 (ES10). It allows you to merge two objects by spreading their properties into a new object. **Other alternatives** If these three approaches are not suitable, other alternatives include: 1. `Object.assign()`: A method that assigns the values of one or more source objects to a target object. 2. Recursive functions: You can write your own recursive function to perform the deep merge operation. 3. Libraries like Immutable.js or MapReduce.js: These libraries offer more advanced data processing and merging capabilities. In summary, this benchmark compares three approaches for performing deep merges on JavaScript objects. Lodash provides a familiar utility function, Ramda offers a fast and concise solution, while the Object spread operator is a new syntax that's easy to read and write.
Related benchmarks:
lodash merge vs deepmerge vs ramda
lodash merge vs deepmerge (updated)
lodash merge vs deepmerge vs Object.assign
lodash merge vs deepmerge vs ramda merge
Comments
Confirm delete:
Do you really want to delete benchmark?