Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs deepmerge vs deepmerge-ts
(version: 0)
Comparing performance of:
lodash vs deepmerge vs deepmerge-ts
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.6.2/lodash.min.js'></script> <script src='https://unpkg.com/deepmerge@4.2.2/dist/umd.js'></script> <script type="module"> import { deepmerge } from 'https://unpkg.com/deepmerge-ts@4.2.1/dist/node/index.mjs'; window.deepmergeTs = deepmerge; </script>
Tests:
lodash
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var c = _.merge({}, a, b); const x = { foo: { bar: 3 }, array: [{ does: 'work', too: [ 1, 2, 3 ] }] } const y = { foo: { baz: 4 }, quux: 5, array: [{ does: 'work', too: [ 4, 5, 6 ] }, { really: 'yes' }] } var z = _.merge({}, x, y);
deepmerge
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var c = deepmerge({}, a, b); const x = { foo: { bar: 3 }, array: [{ does: 'work', too: [ 1, 2, 3 ] }] } const y = { foo: { baz: 4 }, quux: 5, array: [{ does: 'work', too: [ 4, 5, 6 ] }, { really: 'yes' }] } var z = deepmerge({}, x, y);
deepmerge-ts
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var c = deepmerge({}, a, b); const x = { foo: { bar: 3 }, array: [{ does: 'work', too: [ 1, 2, 3 ] }] } const y = { foo: { baz: 4 }, quux: 5, array: [{ does: 'work', too: [ 4, 5, 6 ] }, { really: 'yes' }] } var z = deepmergeTs({}, x, y);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
deepmerge
deepmerge-ts
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
134323.5 Ops/sec
deepmerge
463729.4 Ops/sec
deepmerge-ts
365425.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **Benchmark Overview** The provided benchmark compares the performance of three JavaScript libraries: Lodash, DeepMerge, and DeepMerge-ts. The test cases focus on merging objects with nested structures, demonstrating the efficiency and readability of each library. **Test Cases** Each test case uses a similar structure: 1. Initial objects `a` and `b` are defined. 2. An object `c` (or `z`) is created by merging `a` and `b` using one of the three libraries: Lodash, DeepMerge, or DeepMerge-ts. **Library Explanation** 1. **Lodash**: A popular utility library that provides a wide range of functions for functional programming, data manipulation, and more. The merge function (`_.merge()`) is used to combine two objects into a new object. 2. **DeepMerge**: A lightweight merging library designed specifically for deep object merges. It's optimized for performance and easy to use. In this benchmark, DeepMerge is compared with its TypeScript variant. 3. **DeepMerge-ts**: The TypeScript-compiled version of DeepMerge, allowing it to work seamlessly with JavaScript type checking. **Comparison Options** The three libraries have different approaches: 1. **Lodash**: Uses a recursive function to traverse the object tree and merge values. This approach can be efficient but might lead to slower performance for very deep objects. 2. **DeepMerge**: Employs an iterative, algorithmic approach that avoids recursion and uses caching to optimize performance. 3. **DeepMerge-ts**: Built on top of DeepMerge, it inherits the same iterative approach but with additional type safety features enabled through TypeScript compilation. **Pros and Cons** * **Lodash**: + Pros: Familiarity with Lodash, extensive library, easy to use. + Cons: Can lead to slower performance for deep objects, larger binary size. * **DeepMerge**: + Pros: Lightweight, optimized performance, easy to integrate. + Cons: Less familiar to developers without prior experience, might require more code changes for complex scenarios. * **DeepMerge-ts**: + Pros: Combines the benefits of DeepMerge with TypeScript type safety and checks. + Cons: Additional overhead due to compilation, potential trade-off in performance. **Considerations** When choosing a library for deep object merging: 1. Performance: If speed is crucial, consider using DeepMerge or its variants (e.g., `deepmerge-ts`). 2. Code Readability: For maintainable code with ease of use, Lodash might be the better choice. 3. Integration and Type Safety: When working with TypeScript projects or requiring strong type checking, `DeepMerge-ts` is a good option. **Other Alternatives** Additional libraries that can be used for deep object merging include: * **Immer**: A state management library that supports immutable data structures and provides a simple way to merge objects. * **Fusion**: A lightweight, fast, and efficient deep merge library optimized for performance. Keep in mind that each library has its strengths and weaknesses, and the best choice ultimately depends on your project's specific requirements.
Related benchmarks:
lodash merge vs deepmerge.all
lodash merge vs deepmerge latest CDN
lodash vs deepmerge vs deepmerge-ts vs ts-deepmerge
My lodash vs deepmerge vs deepmerge-ts
Comments
Confirm delete:
Do you really want to delete benchmark?