Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer (setAutoFreeze(false)) vs Lodash cloneDeep 3
(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 < 50000; 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
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 provided benchmark and explain what's being tested, compared, and some pros and cons of each approach. **Benchmark Overview** The benchmark is comparing two JavaScript libraries: Immer and Lodash. Specifically, it's testing how quickly they can update a large dataset (50000 items) with new data. **Immer Library** Immer is a library for functional programming in JavaScript. It provides a simple way to work with immutable data structures by creating "drafts" of the data that can be updated incrementally. The Immer library is used to define a function called `produce` that takes an initial dataset and returns a new, updated version of it. **Lodash Library** Lodash is a utility library for JavaScript that provides a wide range of functions for tasks such as array manipulation, object creation, and string manipulation. In this benchmark, Lodash is used to create a deep clone of the initial dataset using the `cloneDeep` function, which creates a new copy of the data without modifying the original. **Comparison** The benchmark tests how quickly each library can update the large dataset with new data. The Immer library uses its `produce` function to define an update function that takes a draft of the data and updates it incrementally. The Lodash library, on the other hand, uses its `cloneDeep` function to create a new copy of the data and then updates it manually. **Pros and Cons** * **Immer:** + Pros: - Provides an efficient way to work with immutable data structures. - Can be faster for large datasets due to incremental updates. + Cons: - May have higher memory overhead due to creating multiple drafts. - Can be less intuitive for developers without experience with functional programming. * **Lodash:** + Pros: - Well-established and widely adopted library with a large community. - Provides a wide range of utility functions that can be useful in various scenarios. + Cons: - Can be slower due to creating a new copy of the data. - May require more manual effort for updates. **Other Considerations** * **Memory Usage:** Immer may use more memory than Lodash due to its incremental updates, which can lead to higher memory usage. * **Code Complexity:** Immer's API can be less intuitive for developers without experience with functional programming. Lodash's API is generally more familiar to JavaScript developers. **Alternative Libraries** Other libraries that might be used for this type of benchmarking include: * Ramda: A functional programming library that provides a similar interface to Immer. * Redux: A state management library that uses immutable data structures and can be used with Immer or Lodash. * PouchDB: A JavaScript database that uses immutable data structures and can be used for this type of benchmarking. Note that the choice of library ultimately depends on the specific requirements of the project and the expertise of the development team.
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 22
Immer vs shallow vs ramda lens (2)
Comments
Confirm delete:
Do you really want to delete benchmark?