Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash CloneDeep vs Immer Produce
(version: 0)
Comparing performance of:
Produce vs CloneDeep
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/immer@3.1.3/dist/immer.umd.min.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
state = { data: { data1: { data2: 'test' } } };
Tests:
Produce
const result = immer.produce(state, draft => { draft.data.data1.data2 = 'updated' })
CloneDeep
const result = _.cloneDeep(state); result.data.data1.data2 = 'updated';
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Produce
CloneDeep
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
28 days ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Produce
273646.2 Ops/sec
CloneDeep
826848.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided JSON benchmark. **Benchmark Overview** The benchmark compares two functions: `immer.produce` and `_.cloneDeep` from the Lodash library, which are used to create shallow copies of objects. The test aims to measure which approach is faster for creating a shallow copy of an object. **Options Compared** Two options are being compared: 1. **Immer's produce**: This function creates a new state by merging the original state with a draft object that contains the updated values. It returns the updated state. 2. **Lodash's cloneDeep**: This function creates a deep copy of an object, including nested objects and arrays. **Pros and Cons** Here are some pros and cons of each approach: * **Immer's produce**: + Pros: Efficiently updates only the specific parts of the original state, reducing memory allocation and copying overhead. + Cons: Can be slower for large objects due to the merging process. * **Lodash's cloneDeep**: + Pros: Creates a deep copy of the entire object, which can be beneficial when working with complex data structures. + Cons: Copies the entire object, including unnecessary data, leading to increased memory allocation and copying overhead. **Library: Immer** Immer is a library for functional programming in JavaScript. Its primary purpose is to make it easier to work with immutable data structures by providing a simple way to create new versions of objects while keeping the original state intact. In this benchmark, Immer's produce function is used to update only specific parts of the original state, making it more efficient than Lodash's cloneDeep for shallow copying. **Special JS Feature: None** There are no special JavaScript features or syntax used in this benchmark. The code is straightforward and follows standard JavaScript practices. **Other Alternatives** If you need a deeper copy of an object, you can consider using other libraries like: * **JSON.parse() + JSON.stringify()**: This method creates a deep copy by parsing the original object as JSON and then stringifying it. * **lodash.clone**: This function is similar to cloneDeep but creates only shallow copies. However, keep in mind that these alternatives may have different performance characteristics compared to Immer's produce or Lodash's cloneDeep.
Related benchmarks:
lodash get vs native javascript
Immer(produce) vs lodash(cloneDeep)
Lodash CloneDeep vs Immer Produce with heavy load
Ramda vs Lodash CloneDeep vs Immer Produce with heavy load
Comments
Confirm delete:
Do you really want to delete benchmark?