Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer (setAutoFreeze(false)) vs Lodash cloneDeep
(version: 0)
Comparing performance of:
immer vs Lodash
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/immer@0.8.0/dist/immer.umd.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
var { compose, over, set, lensPath, append } = R var INITIAL_DATA = { items: {}, count: 0, keys: [] } for (var index = 0; index < 100; index++) { INITIAL_DATA[index] = { id: index, name: `ITEM-${index}`, value: Math.random() } INITIAL_DATA.count++ INITIAL_DATA.keys.push(index) } var NEW_ITEM_ID = INITIAL_DATA.count +1 var produce = immer.default immer.setAutoFreeze(false)
Tests:
immer
data = produce(INITIAL_DATA, draft => { draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.counter++ draft.keys.push(NEW_ITEM_ID) })
Lodash
data = _.cloneDeep(INITIAL_DATA); data.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } data.counter++ data.keys.push(NEW_ITEM_ID)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
immer
Lodash
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):
Let's break down the benchmark definition and test cases to understand what's being tested. **What is being tested?** The provided JSON represents two individual test cases, each testing a different JavaScript library: Immer and Lodash. **Immer:** Immer is a lightweight immutable data structure library for JavaScript. It allows you to create an immutable version of an object (called a "draft") and then update it in place without modifying the original object. The benchmark definition script uses Immer to create an initial data structure with 100 items, each containing an ID, name, and value. The script then creates a new item with a unique ID and updates the draft using a function that increments the count and adds the new key. **Lodash:** Lodash is a popular utility library for JavaScript that provides a wide range of functional programming helpers. In this benchmark, Lodash is used to clone the initial data structure and then update it manually. The benchmark definition script creates an initial data structure with 100 items, just like Immer. However, instead of using Immer's draft mechanism, Lodash is used to create a deep copy of the original object (using `_.cloneDeep`) and then update the cloned object manually. **Comparison:** In this benchmark, we're comparing the performance of two approaches: 1. **Immer**: Using Immer's immutable data structure and draft mechanism to update the data. 2. **Lodash**: Using Lodash's deep cloning mechanism to create a new copy of the original data and then updating it manually. **Pros and Cons:** **Immer (draft mechanism):** Pros: * Immutable data structures can improve code readability and maintainability. * Immer provides a simple and efficient way to update immutable data structures. Cons: * Can lead to slower performance compared to mutable updates, since a new copy of the object is created. * Requires manual management of drafts to avoid unnecessary copies. **Lodash (deep cloning):** Pros: * Allows for more control over the update process, as you can manually manage the cloned objects. * Can be faster than Immer's draft mechanism if you have a lot of small updates. Cons: * Creates unnecessary copies of large data structures, leading to increased memory usage and slower performance. * Requires manual management of clones, which can lead to errors and bugs. **Other considerations:** Both libraries are well-maintained and widely used in the JavaScript ecosystem. However, the choice between Immer and Lodash depends on your specific use case and performance requirements. If you need to work with immutable data structures frequently, or if you prioritize code readability and maintainability, Immer might be a better choice. If you have large datasets and need more control over updates, Lodash's deep cloning mechanism might be a better fit. **Alternative approaches:** Other libraries that offer similar functionality to Immer include: * **Mocha**: A popular testing library for JavaScript that provides immutable data structures. * **Ponyfill**: A utility library that offers an efficient and readable way to update mutable data structures. For Lodash-style deep cloning, other libraries you might consider include: * **Immutable.js**: A powerful and flexible library for working with immutable data structures. * **Morphism**: A high-performance library for creating and manipulating complex data structures. Ultimately, the choice of library depends on your specific needs and preferences.
Related benchmarks:
Immer vs shallow vs ramda lens
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs cloneDeep of Lodash
Immer (setAutoFreeze(false)) vs Lodash cloneDeep 3
Immer (setAutoFreeze(false)) vs Lodash cloneDeep 22
Immer vs shallow vs ramda lens (2)
Comments
Confirm delete:
Do you really want to delete benchmark?