Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone Large object
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone
Created:
6 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 = { "_id": "5d89d740e050f13d5b65c172", "index": 0, "guid": "85ed8578-6498-4b91-bc46-71a0e56e0ea2", "isActive": false, "balance": "$3,626.01", "picture": "http://placehold.it/32x32", "age": 366, "eyeColor": "green", "name": "Oneil Byrd", "gender": "male", "company": "CEPRENE", "email": "oneilbyrd@ceprene.com", "phone": "+1 (929) 467-2238", "address": "688 Dunne Place, Walker, Rhode Island, 2210", "about": "Occaecat qui sit do reprehenderit ex proident excepteur officia adipisicing id do. Ut non ipsum ullamco reprehenderit duis mollit culpa adipisicing. Velit Lorem cupidatat incididunt cillum aliquip. Minim elit enim laboris duis deserunt incididunt culpa minim nisi.\r\n", "registered": "2017-04-19T11:07:55 -02:00", "latitude": 87.086108, "longitude": -35.085309, "tags": [ "irure", "in", "ex", "eu", "id", "incididunt", "officia", "est", "id", "occaecat", "irure", "labore", "commodo", "adipisicing", "mollit", "esse", "do", "pariatur", "duis", "dolore", "ipsum", "voluptate", "nulla", "cupidatat", "dolore", "veniam", "ea" ], "friends": [ { "id": 0, "name": "Minerva Hancock" }, { "id": 1, "name": "Lucille Mckinney" }, { "id": 2, "name": "Ursula Cummings" }, { "id": 3, "name": "Juana Mann" }, { "id": 4, "name": "Hubbard Martin" }, { "id": 5, "name": "Cheryl Duffy" }, { "id": 6, "name": "Workman Duran" }, { "id": 7, "name": "Geneva Randolph" }, { "id": 8, "name": "Nelson York" }, { "id": 9, "name": "Powers Wyatt" }, { "id": 10, "name": "Sophia Gilliam" }, { "id": 11, "name": "Kidd Eaton" }, { "id": 12, "name": "Caitlin Wall" } ], "greeting": "Hello, Oneil Byrd! You have 9 unread messages.", "favoriteFruit": "apple" }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Json clone
myCopy = JSON.parse(JSON.stringify(MyObject));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
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 Definition and Preparation** The benchmark defines two test cases: 1. **Lodash CloneDeep**: This test case uses Lodash's `cloneDeep` function to create a deep copy of the `MyObject` JSON object. 2. **JSON Clone**: This test case uses the built-in `JSON.parse(JSON.stringify(MyObject))` method to clone the `MyObject` JSON object. **Options Compared** The two options being compared are: * Lodash's `cloneDeep` function * The built-in `JSON.parse(JSON.stringify(MyObject))` method **Pros and Cons of Each Approach** **Lodash CloneDeep** Pros: * Creates a deep copy of the object, including nested arrays and objects. * Handles complex data structures, such as circular references. * Can be more efficient for large objects due to Lodash's optimized implementation. Cons: * Requires an external library (Lodash) to be loaded in the browser. * May have a larger payload due to the inclusion of the Lodash library. **JSON Clone** Pros: * Does not require any additional libraries or payloads. * Is a built-in method, so it's likely to be optimized and efficient. Cons: * Only creates a shallow copy of the object, which may not be sufficient for all use cases (e.g., nested arrays and objects). * Can be slower than Lodash's `cloneDeep` function due to its implementation details. **Library: Lodash** Lodash is a popular JavaScript library that provides a collection of utility functions. In this case, the `cloneDeep` function is used to create a deep copy of the `MyObject` JSON object. Lodash is widely adopted and well-maintained, making it a reliable choice for many developers. **Special JS Feature: None** There are no special JavaScript features or syntax being tested in this benchmark. The focus is on comparing two specific implementation options. **Other Alternatives** If you wanted to test alternative cloning methods, some other options could be: * `JSON.parse(JSON.stringify(MyObject))` with a recursive function (e.g., using a library like Underscore.js) * A custom cloning function implemented from scratch * Other libraries or frameworks that provide cloning functionality (e.g., Ramda) However, for most use cases, Lodash's `cloneDeep` function and the built-in `JSON.parse(JSON.stringify(MyObject))` method are likely to be sufficient.
Related benchmarks:
Lodash cloneDeep vs JSON Clone (Large Object 2)
Lodash cloneDeep vs JSON Clone large Json
Large JSON - Lodash CloneDeep vs JSON Stringify/Parse
Lodash(v4.17.21) cloneDeep vs JSON Clone Larger object
Comments
Confirm delete:
Do you really want to delete benchmark?