Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone vs naive JSON.stringify vs produce
(version: 13)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs JSON.stringify vs Immer Produce
Created:
2 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.21/lodash.min.js' ></script> <script src="https://unpkg.com/immer@9.0.21/dist/immer.umd.production.min.js"></script>
Script Preparation code:
var MyObject = { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject); myCopy.jayson.parse = "something else";
Native structuredClone
myCopy = structuredClone(MyObject); myCopy.jayson.parse = "something else";
JSON.stringify
myCopy = JSON.parse(JSON.stringify(MyObject)); myCopy.jayson.parse = "something else";
Immer Produce
const result = immer.produce(MyObject, draft => { draft.jayson.parse = "something else" });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
JSON.stringify
Immer Produce
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 what's being tested in the provided JSON benchmark. **Benchmark Overview** The benchmark compares four different approaches to create a deep copy of an object: 1. Lodash `cloneDeep` 2. Native `structuredClone` (a new API introduced in JavaScript) 3. `JSON.stringify` and then parsing back with `JSON.parse` 4. Immer's `produce` function **Options Being Compared** Here are the options being compared, along with their pros and cons: 1. **Lodash `cloneDeep`** * Pros: Well-established library, fast, and widely supported. * Cons: Requires an additional library (Lodash), may not be optimal for large objects. 2. **Native `structuredClone`** * Pros: Fast, modern, and optimized for performance. * Cons: Requires a recent JavaScript engine (ECMAScript 2020+) and may have compatibility issues with older browsers or environments. 3. **JSON.stringify + JSON.parse** * Pros: Widely supported, simple to implement, and works across all browsers and environments. * Cons: Can be slower than other options, especially for large objects, due to the overhead of parsing and stringifying. 4. **Immer's `produce` function** * Pros: Optimized for mutation-heavy updates, fast, and integrates well with Immer's immutable state management library. * Cons: Requires an additional library (Immer), may not be suitable for simple deep copying tasks. **Other Considerations** When choosing a deep copying method, consider the following factors: * Performance: If speed is crucial, `structuredClone` or Lodash `cloneDeep` might be good options. * Compatibility: If you need to support older browsers or environments, JSON.stringify + JSON.parse or Lodash `cloneDeep` might be better choices. * Library dependencies: Be aware of the additional libraries required (e.g., Lodash or Immer) and their potential impact on your project's size and complexity. **Special JS Features/ Syntax** None of the test cases use special JavaScript features or syntax that would require a deep understanding of modern JavaScript. However, it's worth noting that `structuredClone` relies on ECMAScript 2020+, which might not be widely supported yet. **Library Descriptions** 1. **Lodash**: A popular utility library for functional programming tasks, including deep copying. 2. **Immer**: An immutable state management library that provides the `produce` function for efficient updates. I hope this explanation helps you understand what's being tested in this benchmark!
Related benchmarks:
Lodash cloneDeep vs structuredClone vs JSON.stringify (small object)
Lodash (4.17.11) cloneDeep vs JSON Clone vs structuredClone
Lodash cloneDeep vs structuredClone vs Json.stringify
lodash clonedeep vs json.parse(stringify()) vs structuredClone
lodash cloneDeep vs. JSON.parse(JSON.stringify()) vs. structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?