Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone vs JSON Parse
(version: 0)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs JSON Parse
Created:
4 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 Parse
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 Parse
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1714215.1 Ops/sec
Native structuredClone
662993.8 Ops/sec
JSON Parse
1773321.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark test case for comparing the performance of three different approaches: Lodash's `cloneDeep`, Web API's `structuredClone`, and `JSON.parse(JSON.stringify())`. **Approaches Compared** 1. **Lodash cloneDeep**: This is a widely used library function that creates a deep copy of an object, handling cycles and nested objects. 2. **Web API's structuredClone**: Introduced in ECMAScript 2020, this function provides a new way to create deep copies of objects without the need for libraries like Lodash. 3. **JSON Parse (JSON Stringify)**: This approach creates a shallow copy of an object by serializing it as a JSON string and then parsing it back into an object. **Pros and Cons of Each Approach** 1. **Lodash cloneDeep**: * Pros: + Widely supported and maintained. + Handles cycles and nested objects efficiently. * Cons: + Requires the Lodash library, which adds overhead. + May not be optimized for performance in all scenarios. 2. **Web API's structuredClone**: * Pros: + Part of the standard JavaScript API, no additional libraries required. + Optimized for performance and handling cycles efficiently. * Cons: + Still relatively new (ECMAScript 2020), may not be fully supported by older browsers or versions. 3. **JSON Parse (JSON Stringify)**: * Pros: + Lightweight and fast, as it only requires basic JavaScript functionality. * Cons: + Creates a shallow copy, which might not be suitable for all use cases. + Requires serializing the object to a string first, which can lead to additional overhead. **Library and Purpose** The Lodash library is a popular JavaScript utility library that provides various helper functions for tasks like array manipulation, functional programming, and more. In this case, `cloneDeep` is used to create deep copies of objects. **Special JS Feature or Syntax** There are no specific JS features or syntaxes being tested in this benchmark, apart from the use of ECMAScript 2020's `structuredClone` function. **Alternatives** If you need alternatives to these approaches: 1. **Other deep copy libraries**: If you prefer a more robust and feature-rich library than Lodash for deep copying, consider using other libraries like `lodash-es` or ` deep-copy`. 2. **Native methods**: For shallow copies, using `Object.assign()` or `JSON.parse(JSON.stringify())` might be sufficient. 3. **Custom implementation**: If performance is critical, you can also implement your own deep copying algorithm from scratch. In summary, the choice of approach depends on your specific requirements, performance considerations, and personal preference for library usage.
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-Clone
Lodash cloneDeep vs structuredClone vs JSON-JSON
Lodash cloneDeep vs structuredClone vs Json.stringify
Comments
Confirm delete:
Do you really want to delete benchmark?