Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
is lodash cloneDeep the BEST object deep cloner ? what about native structuredClone function ?
(version: 2)
Comparing performance of:
lodash cloneDeep vs my super deep cloner yeah vs structuredClone
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'> const _ = lodash </script>
Tests:
lodash cloneDeep
_.cloneDeep({ prop: { subprop: 'value' } })
my super deep cloner yeah
const trueclone = (obj) => { const cloned = Array.isArray(obj) ? [] : {} const keys = Object.keys(obj) const values = Object.values(obj) const length = keys.length for (let i = 0; i < length; i++) { if (typeof values[i] === 'object') values[i] = trueclone(values[i]) cloned[keys[i]] = values[i] } return cloned } trueclone({ prop: { subprop: 'value' } })
structuredClone
structuredClone({ prop: { subprop: 'value' } })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash cloneDeep
my super deep cloner yeah
structuredClone
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. **Overview** The benchmark is comparing three different approaches to create a deep clone of an object: Lodash's `cloneDeep`, a custom implementation called "my super deep cloner", and the native JavaScript function `structuredClone`. **Options Compared** 1. **Lodash's `cloneDeep`**: This is a popular library for working with JSON data in JavaScript. `cloneDeep` creates a deep clone of an object by recursively iterating over its properties and creating new objects for each level of nesting. 2. **Custom Implementation ("my super deep cloner")**: This implementation uses a custom function to create a deep clone of an object. It iterates over the object's keys, values, and nested objects, creating new objects and assigning values from the original object to the cloned objects. 3. **Native JavaScript Function `structuredClone`**: Introduced in ECMAScript 2020, `structuredClone` is a built-in function that creates a deep clone of an object by recursively iterating over its properties. **Pros and Cons** 1. **Lodash's `cloneDeep`**: * Pros: Widely used, well-maintained library with many features (e.g., support for arrays, functions, maps). * Cons: Adds external dependency (Lodash), might be slower than custom implementations. 2. **Custom Implementation ("my super deep cloner")**: * Pros: No external dependencies, can be optimized for specific use cases. * Cons: Requires manual implementation and maintenance, may be more error-prone than using a library like Lodash. 3. **Native JavaScript Function `structuredClone`**: * Pros: Built-in function, no external dependencies, efficient implementation. * Cons: Not widely supported in older browsers (pre-2020), might not support all features of the custom implementation. **Library and Purpose** Lodash is a popular utility library for JavaScript that provides a wide range of functions for working with data structures, such as arrays, objects, and functions. `cloneDeep` is one of its most useful functions, allowing developers to create deep clones of complex data structures. **Special JS Feature or Syntax** There isn't any specific JavaScript feature or syntax mentioned in the benchmark. However, it's worth noting that `structuredClone` uses a proprietary mechanism (not part of the ECMAScript standard) to clone objects, which might not be compatible with older browsers or environments. **Other Alternatives** If you need an alternative deep cloning library, some popular options include: * Immer: A lightweight library for working with immutable data structures. * Ramda: A functional programming library that includes a `cloneDeep` function. * Immutable.js: A library for working with immutable data structures in JavaScript. Keep in mind that these alternatives might have different trade-offs and use cases compared to Lodash's `cloneDeep`.
Related benchmarks:
Comparing deep cloning methods (small object): Lodash <> Custom clone func <> JSON.parse <> structuredClone
Comparing deep cloning methods (small object): Lodash <> Custom clone func <> JSON.parse <> structuredClone 2
Object Clone Lodash vs structuredClone
JS Cloning benchmarking
Comments
Confirm delete:
Do you really want to delete benchmark?