Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ramda vs lodash.merge vs deepmerge
(version: 0)
Comparing performance of:
lodash vs deepmerge vs ramda
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://raw.githubusercontent.com/lodash/lodash/4.17.19/npm-package/lodash.js'></script> <script src='https://unpkg.com/deepmerge@4.2.2/dist/umd.js'></script> <script src="//cdn.jsdelivr.net/npm/ramda@latest/dist/ramda.min.js"></script>
Script Preparation code:
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var x = { foo: { bar: 3 }, array: [{ does: 'work', too: [1, 2, 3] }] }; var y = { foo: { baz: 4 }, quux: 5, array: [{ does: 'work', too: [4, 5, 6] }, { really: 'yes' }] };
Tests:
lodash
var c = _.merge({}, a, b); var z = _.merge({}, x, y);
deepmerge
var c = deepmerge({}, a, b); var z = deepmerge({}, x, y);
ramda
var c = R.mergeAll({}, a, b); var z = R.mergeAll({}, x, y);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
deepmerge
ramda
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
271210.9 Ops/sec
deepmerge
723589.9 Ops/sec
ramda
3009850.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmarking process. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmarking test case. It defines three individual tests, each using a different library to merge two objects: 1. `lodash.merge` 2. `deepmerge` 3. `ramda.mergeAll` These libraries are used for deep object merging. **Library Overview and Purpose** * **Lodash**: Lodash is a popular JavaScript utility library that provides a wide range of functions, including the `merge` function. The `merge` function allows you to combine two objects into one, recursively merging properties as needed. * **DeepMerge**: DeepMerge is another library specifically designed for deep object merging. It's optimized for performance and can handle complex merge scenarios. * **Ramda**: Ramda is a functional programming library that includes the `mergeAll` function. This function merges multiple arrays or objects into one, while also handling nested structures. **Options Compared** In this benchmark, the same input objects (`a`, `b`, `x`, and `y`) are used as inputs for each test case. The differences lie in how the merge functions handle the nested structure of these objects: * **Lodash**: Lodash's `merge` function will recursively merge properties from both objects, but it might not preserve the original object structure. * **DeepMerge**: DeepMerge is designed to produce a deep clone of one of the input objects and then merge the other object into that clone, preserving the original structure. * **Ramda**: Ramda's `mergeAll` function merges all input arrays or objects into one, but it can't be used directly with nested structures like this. Instead, you'd need to use `R.mergeAll` with an array of objects. **Pros and Cons** Here are some pros and cons for each library: * **Lodash**: Pros: + Wide range of utility functions + Easy to learn and use Cons: + Not specifically designed for deep object merging + Might not preserve original structure * **DeepMerge**: Pros: + Optimized for performance + Preserves original structure Cons: + Limited functionality compared to Lodash + Might be overkill for simple merge tasks * **Ramda**: Pros: + Functional programming benefits + Can handle complex data structures Cons: + Steeper learning curve due to functional programming concepts + Not directly designed for deep object merging **Other Considerations** When choosing a library, consider the following factors: * Performance: DeepMerge is optimized for performance, but Lodash's `merge` function might be faster in some cases. * Code readability and maintainability: Lodash's API is generally more readable and intuitive than Ramda's, while DeepMerge's API is concise but less well-known. * Data structure handling: If you need to handle complex nested structures or arrays, Ramda's `mergeAll` function might be a better choice. **Alternatives** If none of these libraries are suitable for your use case, consider the following alternatives: * **Immutable.js**: A library that focuses on immutable data structures and provides a deep merge function. * **lodash-es**: A variant of Lodash with additional features, including a more modern API and improved performance. * **jsdeep**: A library designed specifically for deep object merging, with a focus on performance and ease of use.
Related benchmarks:
lodash merge vs deepmerge 2
Deep merge: lodash vs ramda vs Object spread
lodash merge vs deepmerge latest
lodash merge vs deepmerge vs Object.assign
lodash merge vs deepmerge 4.2.2 vs own merge implementation
Comments
Confirm delete:
Do you really want to delete benchmark?