Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Custom Lydnon Lodash cloneDeep vs JSON
(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": 122, "name": "regressiontime", "entity_type": "Export", "entity_id": 517478, "agent_type": "PrinterAccountFormat", "agent_id": 107, "permalink": null, "details": { "artwork_details": { "qty": "100", "stock": "high gloss", "thumbnail_url": "http://local.awsdev.net:3000/assets/no_thumbnail-f42bbe0032da84ef7721eafc77a6a1ae3ff30c1e0c7f24f811e26fe8f71b0332.png", "name": "1576021552_Poster_A1_Print.pdf", "format": "A1 Print", "size": "608.82 x 855.82 (mm)", "color": "Process CYMK", "price": 45 }, "invoice_details": { "email": "lyndon@outfit.io", "phone": "0400 000 000", "address": "17, South Brisbane, QLD, 4101", "company": "outfitio", "cc_email": "", "invoice_to": "lyndon" }, "additional_notes": { "_notes": "" }, "delivery_details": { "email": "lyndon@outfit.io", "phone": "0400 000 000", "address": "17, South Brisbane, QLD, 4101", "company": "outfitio", "cc_email": "", "invoice_to": "lyndon" }, "printer_details": { "printer": "Ash's Print Shop", "email": [ "ashley+1000@outfit.io" ], "copied": [], "phone": "0458209203", "address": "46 raleigh street\nSpringwood QLD \nAustralia", "notes": null } }, "name_or_id": "regressiontime", "parent_id": null, "delivery_items": [], "project_id": 67169 } 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 world of microbenchmarks and explore what's being tested on this provided JSON. **Benchmark Definition:** The benchmark is comparing two approaches for creating a deep copy of an object: using Lodash's `cloneDeep` function (`Lodash cloneDeep`) versus using JavaScript's built-in `JSON.parse(JSON.stringify())` method (`Json clone`). **What are the options being compared?** 1. **Lodash cloneDeep**: A popular utility library that provides various functions for manipulating data, including deep cloning. 2. **JSON.parse(JSON.stringify())**: A built-in JavaScript method that creates a new object by recursively copying all properties from an existing object. **Pros and Cons of each approach:** **Lodash cloneDeep:** Pros: * Faster execution times due to optimized implementation * Supports more complex data structures, such as arrays and objects with circular references * Easier to use and understand for developers familiar with Lodash Cons: * Requires including an additional library (Lodash) in the build process * May have dependencies on other libraries or modules **JSON.parse(JSON.stringify()):** Pros: * No external dependencies required * Can be used as a simple, lightweight alternative for basic cloning needs * Built-in and widely supported by most browsers Cons: * Can be slower due to the overhead of parsing JSON strings * May not work correctly with complex data structures or circular references **Other considerations:** * The benchmark is executed on Firefox 72 on Windows Desktop. * The `ExecutionsPerSecond` value indicates how many executions are performed per second, which can affect the overall performance result. **Library and syntax explanations:** * Lodash is a JavaScript utility library that provides various functions for manipulating data, including deep cloning. It's widely used in the JavaScript community and has an extensive set of features. * `JSON.parse(JSON.stringify())` uses the JSON stringification method to create a new object by recursively copying all properties from the original object. **Special JS feature or syntax:** None mentioned in this benchmark. **Alternatives:** If you need alternative cloning methods, you can consider using: * `Array.prototype.slice()`: Creates a shallow copy of an array. * `Object.assign()`: Creates a new object by copying all own properties from one or more source objects. * `immer`: A library for creating immutable data structures. Keep in mind that the best approach depends on your specific use case, performance requirements, and personal preferences.
Related benchmarks:
Lodash cloneDeep vs JSON Clone Large object
Lodash cloneDeep vs JSON Clone Larger object
Lodash cloneDeep vs JSON Clone zzz
Lodash(v4.17.21) cloneDeep vs JSON Clone Larger object
Comments
Confirm delete:
Do you really want to delete benchmark?