Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash CloneDeep vs Immer Produce with heavy load
(version: 0)
Comparing performance of:
Produce vs CloneDeep
Created:
3 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', }, data3: Array.from({length: 1000}).map(() => document.createElement('div')) } };
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser/OS:
Chrome 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Produce
691593.0 Ops/sec
CloneDeep
2114.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided JSON represents a benchmark test case for measuring the performance of two different approaches: Immer's `produce` function and Lodash's `cloneDeep` function. **What is being tested?** In this benchmark, we have a complex data structure `state`, which consists of an object `data` with multiple nested objects and arrays. The goal is to update the value of `data.data1.data2` using two different approaches: 1. Immer's `produce` function: This function creates a new copy of the original data structure, allowing us to safely mutate it without affecting the original. 2. Lodash's `cloneDeep` function: This function creates a deep clone of the original data structure, which can be used to create a new independent copy. **Options being compared** We are comparing two options: 1. **Immer's produce**: Immer is a library that provides immutable data structures and functions for working with them. `produce` is a specific function that creates a new copy of the original data structure, allowing us to update it without affecting the original. 2. **Lodash's cloneDeep**: Lodash is a utility library that provides various functions for working with data, including cloning and mutating. `cloneDeep` is a specific function that creates a deep clone of the original data structure. **Pros and Cons** Here are some pros and cons of each approach: **Immer's produce** Pros: * Immutability ensures thread-safety and prevents unexpected side effects. * Can be more efficient than cloning, especially for large data structures. Cons: * Creates a new copy of the data structure, which can be memory-intensive. * May not be suitable for very large or complex data structures due to performance overhead. **Lodash's cloneDeep** Pros: * Provides a deep clone of the original data structure, allowing for independent updates. * Can be more flexible than Immer's produce, as it allows for arbitrary mutations. Cons: * Cloning can be memory-intensive and slow for very large data structures. * May not ensure immutability, leading to unexpected side effects if not used carefully. **Other considerations** When using either approach, consider the following: * Make sure to use `produce` with caution when working with very large or complex data structures, as it can lead to performance issues. * Use `cloneDeep` with care when updating large data structures, as it can consume a significant amount of memory. **Library and its purpose** Immer is a library that provides immutable data structures and functions for working with them. Its primary goal is to help developers write more predictable, reliable, and concurrent code. Lodash is a utility library that provides various functions for working with data, including cloning, mutating, and transforming. Its primary goal is to provide a comprehensive set of tools for common data-related tasks. **Special JS feature or syntax** This benchmark does not use any special JavaScript features or syntax beyond the standard language features provided by the browsers and Node.js environments used to run it.
Related benchmarks:
Lodash CloneDeep vs Immer Produce
lodash get vs native javascript
Immer(produce) vs lodash(cloneDeep)
Ramda vs Lodash CloneDeep vs Immer Produce with heavy load
Comments
Confirm delete:
Do you really want to delete benchmark?