Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs structured Clone vs json parse
(version: 0)
Comparing performance of:
Lodash vs Structured Clone API vs JSON Parse
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
myCopy = _.cloneDeep(MyObject);
Structured Clone API
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
Structured Clone API
JSON Parse
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
1224300.2 Ops/sec
Structured Clone API
572172.4 Ops/sec
JSON Parse
1096192.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested on the provided JSON?** The benchmark tests three different approaches to create a deep copy of an object in JavaScript: 1. **Lodash**: The `cloneDeep` function from the Lodash library is used to create a deep copy of the `MyObject`. 2. **Structured Clone API**: The `structuredClone` function, which is part of the WebAssembly (WASM) standard, is used to create a deep copy of the `MyObject`. 3. **JSON Parse**: The `JSON.parse(JSON.stringify(MyObject))` method is used to create a deep copy of the `MyObject`. This approach serializes the object to a JSON string, then parses it back into an object. **Options comparison** The benchmark compares the execution time and performance of these three approaches: * **Lodash**: The Lodash library provides a robust set of functions for array manipulation, string manipulation, and other utility functions. `cloneDeep` is specifically designed to create deep copies of objects. * **Structured Clone API**: This approach uses the WebAssembly standard's structured clone algorithm to create a deep copy of the object. * **JSON Parse**: This approach serializes the object to a JSON string using `JSON.stringify()`, then parses it back into an object using `JSON.parse()`. **Pros and Cons** Here are some pros and cons for each approach: * **Lodash**: Pros: + Well-tested and widely used library + Supports deep copying of complex objects + Can handle a wide range of data types * Cons: + Additional dependency (the Lodash library) + May have performance overhead due to the library's complexity * **Structured Clone API**: + Fast and efficient, with no additional dependencies + Specifically designed for WebAssembly, which can lead to better performance + However, it may not be as widely supported or tested as other libraries * **JSON Parse**: Pros: + Lightweight and simple implementation + No additional dependencies required * Cons: + May have performance overhead due to the serialization and parsing steps + Not specifically designed for deep copying complex objects **Other considerations** * The benchmark results may vary depending on the specific use case, data size, and system configuration. * The Lodash library provides more features than just `cloneDeep`, such as array manipulation functions. However, these are not relevant to this specific benchmark. **Library descriptions** * **Lodash**: A JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string manipulation, and data transformation. * **Structured Clone API**: A WebAssembly standard that provides an efficient way to create deep copies of objects. This is not a separate library but rather a part of the WebAssembly standard. **Special JS features or syntax** The benchmark uses the `structuredClone` function, which is a relatively new feature in JavaScript (introduced in ECMAScript 2021). This function provides an efficient way to create deep copies of objects and is specifically designed for use with WebAssembly.
Related benchmarks:
Lodash cloneDeep vs JSON.parse(JSON.stringify())
Lodash (4.17.11) cloneDeep vs JSON Clone vs structuredClone
Lodash cloneDeep vs structuredClone vs Json.stringify
lodash cloneDeep vs. JSON.parse(JSON.stringify()) vs. structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?