Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone vs JSON
(version: 0)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs JSON plain
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.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);
Native structuredClone
myCopy = structuredClone(MyObject);
JSON plain
myCopy = JSON.parse(JSON.stringify(MyObject))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
JSON plain
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 dive into the explanation of the provided benchmark. **Benchmark Overview** The benchmark compares three methods for creating a deep copy of an object: Lodash's `cloneDeep` function, the native `structuredClone` API, and the JSON serialization approach using `JSON.parse(JSON.stringify())`. The test is designed to measure the performance of each method on different browsers and devices. **Options Compared** The benchmark compares the following options: 1. **Lodash cloneDeep**: A popular JavaScript library that provides a function for creating deep copies of objects. 2. **Native structuredClone**: The native Web API for creating deep copies of objects, introduced in ECMAScript 2020. 3. **JSON plain**: The JSON serialization approach using `JSON.parse(JSON.stringify())`, which is not as efficient as the other two methods. **Pros and Cons** * **Lodash cloneDeep**: Pros: + Well-established library with a wide range of use cases. + Supports various features like deep cloning, array manipulation, and more. + Well-tested and widely used. * Cons: + Adds an external dependency (the Lodash library). + May have overhead due to the library's complexity. * **Native structuredClone**: Pros: + Native API, meaning no additional dependencies are required. + Designed specifically for deep cloning, making it efficient. + Part of the ECMAScript standard, ensuring interoperability. * Cons: + Relatively new API (introduced in ECMAScript 2020), which might lead to less adoption and testing. * **JSON plain**: Pros: + No external dependencies required. + Simple and lightweight approach. * Cons: + Not designed for deep cloning, leading to potential performance issues. **Library and Syntax Considerations** * **Lodash cloneDeep**: A popular utility library that provides a wide range of functions for working with JavaScript data structures. The `cloneDeep` function is specifically designed for creating deep copies of objects. * **Native structuredClone**: Introduced in ECMAScript 2020, this API provides a simple and efficient way to create deep clones of objects. It's designed to work across multiple platforms and browsers. **Special JS Features or Syntax** None are explicitly mentioned in the benchmark definition or test cases. **Alternatives** If you're looking for alternative approaches to creating deep copies of objects, consider the following: * **JSON.stringify() + JSON.parse()**: This approach is simple but not as efficient as the other two methods. * **For...in loops**: This method involves manually iterating over the object's properties and creating a new copy. It can be error-prone and inefficient. * **Other libraries**: Depending on your specific use case, you might find alternative libraries or approaches that better suit your needs. In summary, the benchmark provides an excellent comparison of three methods for creating deep copies of objects: Lodash's `cloneDeep` function, the native `structuredClone` API, and the JSON serialization approach using `JSON.parse(JSON.stringify())`. The results will help you understand the performance differences between these approaches on different browsers and devices.
Related benchmarks:
Lodash cloneDeep vs structuredClone vs JSON clone s
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-Clone
Lodash cloneDeep vs structuredClone vs Json.stringify
Comments
Confirm delete:
Do you really want to delete benchmark?