Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash CloneDeep vs Immer Produce on larger array
(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 = [ {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}}, {data1: {data2: 'test'}} ];
Tests:
Produce
const result = immer.produce(state, draft => { draft[5].data1.data2 = 'updated' })
CloneDeep
const result = _.cloneDeep(state); result[5].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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Produce
153362.0 Ops/sec
CloneDeep
30993.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark definition and explain what's being tested, compared, and their pros and cons. **Benchmark Definition:** The benchmark is comparing two functions: `immer.produce` from the Immer library and `_cloneDeep` from Lodash. Both functions aim to create a deep copy of an object (in this case, an array of objects). **What's being tested?** * `immer.produce`: This function creates a new copy of the original state by modifying a draft version of it. The purpose is to detect when changes are made to the original state. * `_cloneDeep`: This function creates a deep clone of the original state, which means creating an entirely new object with identical properties and structure. **Options being compared:** 1. **Immer's `produce`**: Creates a new copy of the original state by modifying a draft version of it. 2. **Lodash's `_cloneDeep`**: Creates a deep clone of the original state. **Pros and Cons:** * **Immer's `produce`**: + Pros: - More efficient, as it only modifies the draft copy and not the entire object tree. - Can be faster for larger objects due to less overhead. + Cons: - May not work correctly if the original state is modified concurrently with the produce operation. - Requires a separate draft version of the state, which can add complexity. * **Lodash's `_cloneDeep`**: + Pros: - Guaranteed to create an exact copy of the original state, regardless of concurrent modifications. - Simple and straightforward implementation. + Cons: - Can be slower than Immer's `produce`, as it needs to recursively clone the entire object tree. **Other considerations:** * The benchmark is comparing the performance of these two functions on a large array of objects. This is relevant for use cases where data needs to be cloned or updated frequently. * The Immer library is designed specifically for working with immutable state, making `produce` an efficient choice for managing state changes. **Library and syntax:** * **Immer**: A library for building and managing immutable state. It provides a range of functions for creating, updating, and manipulating state objects. + Purpose: To simplify the management of complex, interconnected data structures while ensuring immutability. * **Lodash**: A utility library providing functional programming helpers, including cloning functions. + Purpose: To provide a set of reusable functions for common tasks, such as array manipulation and object creation. In summary, this benchmark compares two approaches to creating deep copies of objects: Immer's `produce` (modifying a draft copy) and Lodash's `_cloneDeep` (creating an exact clone). The choice between these options depends on the specific use case and performance requirements.
Related benchmarks:
array shallow clone comparison narrowed
array of objects shallow clone comparison narrowed
Spread Operator vs. Lodash for POJO
Deep clone: lodash vs ramda
Immer produce() vs Lodash cloneDeep() vs AngularJS copy() vs JSON.parse()
Comments
Confirm delete:
Do you really want to delete benchmark?