Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep merge lodash vs ramda vs deepmerge vs Immutable
(version: 5)
Comparing performance of:
Ramda.mergeDeepRight vs Lodash.merge vs deepmerge vs Immutable
Created:
2 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="//cdn.jsdelivr.net/npm/ramda@latest/dist/ramda.min.js"></script> <script src="https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/lodash.js"></script> <script src="https://unpkg.com/deepmerge/dist/umd.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/immutable/4.3.4/immutable.min.js'></script>
Script Preparation code:
var obj1 = { a: 10, b: { b1: 'Hello', b2: { b2a: [1, 2, 3], b2b: { b2b1: 'Deep', b2b2: [4, 5, 6], b2b3: { b2b3a: 11, b2b3b: 'Nested' } } } }, c: [7, 8, 9], d: 'World' }; var obj2 = { a: 15, b: { b1: 'Hola', b2: { b2a: [10, 11, 12], b2b: { b2b1: 'Profundo', b2b2: [13, 14, 15], b2b3: { b2b3a: 16, b2b3b: 'Anidado', b2b3c: 'Nuevo Campo' } } }, b3: 'Nuevo Campo' }, e: 'Mundo', f: { f1: [16, 17, 18], f2: { f2a: 'Adicional', f2b: { f2b1: 17, f2b2: 'Más Profundo' } } } };
Tests:
Ramda.mergeDeepRight
R.mergeDeepRight(obj1, obj2)
Lodash.merge
_.merge(obj1, obj2)
deepmerge
deepmerge(obj1, obj2)
Immutable
var g = Immutable.mergeDeep(obj1, obj2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Ramda.mergeDeepRight
Lodash.merge
deepmerge
Immutable
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Ramda.mergeDeepRight
2446494.2 Ops/sec
Lodash.merge
411156.4 Ops/sec
deepmerge
261771.0 Ops/sec
Immutable
413240.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks. **Benchmark Definition** The benchmark is designed to compare the performance of four different libraries for performing deep merges: 1. Lodash (`_.merge`) 2. Ramda (`Ramda.mergeDeepRight`) 3. Deep Merge (`deepmerge`) 4. Immutable (`Immutable.mergeDeep`) **What are we testing?** We're testing how quickly each library can merge two objects, `obj1` and `obj2`, while preserving the structure of the original objects. **Options compared** The four libraries have different approaches to performing deep merges: * Lodash uses a simple recursive approach, where it iterates through the properties of both objects and combines them. * Ramda uses a functional programming style, where it uses higher-order functions to compose the merge operation. `mergeDeepRight` is similar to Lodash's approach but with some additional features. * Deep Merge uses a more efficient algorithm that avoids unnecessary copies of data. * Immutable uses a immutable data structure approach, where it creates a new object that represents the merged result. **Pros and Cons** Here are some pros and cons for each library: * Lodash: + Pros: Simple to use, well-documented, widely supported. + Cons: Not optimized for performance, can create unnecessary copies of data. * Ramda: + Pros: Functional programming style, composability, good performance. + Cons: Steeper learning curve, may be overkill for simple merges. * Deep Merge: + Pros: Optimized for performance, efficient algorithm. + Cons: Limited documentation, less widely supported than other libraries. * Immutable: + Pros: Immutable data structure approach, predictable behavior. + Cons: Can be slower due to the overhead of creating new objects. **Library explanations** 1. Lodash (`_.merge`): Lodash is a popular utility library that provides a wide range of functions for common tasks, including array manipulation and object merging. The `merge` function takes two objects as input and returns a new object with the combined properties. 2. Ramda (`Ramda.mergeDeepRight`): Ramda is a functional programming library that provides a series of higher-order functions for composing operations. `mergeDeepRight` is similar to Lodash's approach but uses a more functional programming style, which can lead to more predictable and composable code. 3. Deep Merge (`deepmerge`): Deep Merge is a lightweight library specifically designed for deep merging objects. It uses an efficient algorithm that avoids unnecessary copies of data. 4. Immutable (`Immutable.mergeDeep`): Immutable is a library that provides immutable data structures and algorithms for manipulating them. `mergeDeep` uses this approach to create a new object with the combined properties. **Other alternatives** If you're interested in exploring other libraries or approaches, here are some alternatives: * Other deep merging libraries: Such as merge-deep or merge-object. * Immutable data structure libraries: Such as MuJS or TypeScript's built-in immutable types. * Functional programming libraries: Such as Elm or Haskell. I hope this explanation helps! Let me know if you have any further questions.
Related benchmarks:
Deep merge: lodash vs ramda vs Object spread
lodash merge vs object.assign vs spread with deep values
lodash merge vs deepmerge (updated FIXED)
deep merge vs custom
Comments
Confirm delete:
Do you really want to delete benchmark?