Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer (setAutoFreeze(false)) vs Lodash cloneDeep 22
(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 dive into the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares the performance of two JavaScript libraries: Immer and Lodash, in terms of creating a new copy of an object using the `cloneDeep` function from Lodash or the `immer.default` function with custom configuration. **What's Being Tested?** In this benchmark, we have two test cases: 1. **Immer (setAutoFreeze(false))**: This test case uses Immer to create a new copy of the initial data using the `immer.default` function. The `setAutoFreeze(false)` option tells Immer not to automatically freeze the draft object after each operation. 2. **Lodash cloneDeep**: This test case uses Lodash's `cloneDeep` function to create a deep copy of the initial data. **Options Compared** In this benchmark, we have two main options: 1. **Immer with custom configuration**: Immer provides an alternative way to create a new copy of an object using its own `immer.default` function. This approach uses a more functional programming style and can be more efficient than the traditional `cloneDeep` method. 2. **Lodash cloneDeep**: Lodash's `cloneDeep` function creates a deep copy of an object by recursively cloning all properties. **Pros and Cons** Here are some pros and cons of each approach: 1. **Immer with custom configuration** * Pros: * More efficient memory usage since it doesn't create a new scope for each operation. * Less overhead compared to the traditional `cloneDeep` method. * Cons: * Requires more code and setup than Lodash's `cloneDeep`. * Can be slower due to the additional function call overhead. 2. **Lodash cloneDeep** * Pros: * Easy to use and well-documented. * Widely supported and widely adopted in the JavaScript community. * Cons: * More memory-intensive since it creates a new scope for each operation. * Can be slower due to the overhead of creating a new object. **Library Descriptions** * **Immer**: Immer is a popular JavaScript library for working with immutable data structures. It provides an alternative way to create new copies of objects using its own `immer.default` function. Immer aims to reduce memory usage and improve performance by avoiding the creation of unnecessary scopes. * **Lodash**: Lodash is a comprehensive utility library that provides various functions, including `cloneDeep`, for working with JavaScript data structures. **Special JS Features/Syntax** In this benchmark, we don't see any special JavaScript features or syntax being used. However, it's worth noting that Immer uses a functional programming style, which can make the code more concise and easier to read. **Alternatives** If you're interested in exploring alternative libraries for creating deep copies of objects, here are some options: * **Radium**: Radium is another JavaScript library that provides an immutable data structure framework. It's similar to Immer but with a different implementation. * **Preact**: Preact is a lightweight JavaScript library that aims to provide better performance and rendering capabilities compared to React. I hope this explanation helps you understand the benchmark being tested!
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 vs shallow vs ramda lens (2)
Comments
Confirm delete:
Do you really want to delete benchmark?