Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Vs Structured Vs recurcive Vs Json
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs recursiveDeepCopy vs Json Clone
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 = { "id": 4004800, "name": "Multi Drop Bucket322101410", "grade": "Grade 6", "status": 3000200, "user_id": 2, "version": 2, "grade_id": 149, "item_json": { "uuid": "88ed52c-db67-a72e-5418-a08728b171b", "dropSlot": true, "matchList": [ { "id": "163140-7bbd-ea8b-d8a-2b4ca2b5572", "header": "<p>Category1</p>", "noOfDropSlots": 2 }, { "id": "4384ef8-006e-def8-c11-1d7e5b87fb", "header": "<p>Category2</p>", "noOfDropSlots": 3 } ], "optionList": [ { "id": "1c7a2fd-0574-04d5-48dc-135820a5", "header": "<p>Input1</p>", "dragOptionList": [ { "id": "eeac105-0d43-3e6d-b24a-7807ed84bd6", "optionText": "<p>Option1</p>" }, { "id": "876ae37-dfa6-d221-5d61-0ec718c1dc", "optionText": "<p>Option2</p>" } ] }, { "id": "0732c48-427-62e-2e4-3bd31764e36c", "header": "<p>Input2</p>", "dragOptionList": [ { "id": "28da14-77af-116a-a46d-32cfbc3004", "optionText": "<p>Option3</p>" }, { "id": "f8e507-53d-4b8-3315-d128a6587a04", "optionText": "<p>Option4</p>" } ] } ], "stickyDrop": true, "stemContent": "<p>click <span class=\"text-tag-accessibility\" data-access-id=\"cke-atp-e8d1aca531b57b754cb45c7e264032404\"> Sound</span></p><p> </p>", "itemTypeCode": "MDB", "minItemWidth": 8, "minItemHeight": 9, "correctResponse": [ { "id": "163140-7bbd-ea8b-d8a-2b4ca2b5572", "values": [ "eeac105-0d43-3e6d-b24a-7807ed84bd6" ] }, { "id": "4384ef8-006e-def8-c11-1d7e5b87fb", "values": [] } ] }, "max_score": 34, "rationale": { "optionList": [ { "id": "163140-7bbd-ea8b-d8a-2b4ca2b5572", "rationaleText": "" }, { "id": "4384ef8-006e-def8-c11-1d7e5b87fb", "rationaleText": "" } ] }, "accessArray": [ { "key": "cke-atp-e8d1aca531b57b754cb45c7e264032404", "field": null, "signed": { "Signed_English": { "filePath": "/media/15009/accessibility/item/4004800/86a8fc-234-d4ec-70d0-d41aa34f1231/Lightbulbs%20Moving%20in%20the%20Wind%20%281%29" } }, "spoken": { "textAndGraphics": { "soundPath": "media/15009/accessibility/item/4004800/1717-1187-3ec4-db83-46fcc2f62f1e.mp3", "synthSpeech": " Sound", "defaultOrder": 1, "onDemandOrder": 1 } }, "braille": { "English_Braille": { "filePath": "/media/15009/accessibility/item/4004800/4552544-f7c6-fa8a-f63-2b5fac5a4c6c/brfsample" } }, "keyword": { "DE": "Text6" }, "accommodation_ids": [ 4006886, 4006887, 4006888, 4006889 ] } ], "description": null, "previous_id": null, "content_area": "English Language Arts", "created_date": "2022-10-14T09:36:02.958589+00:00", "item_type_id": 3000168, "scoring_data": { "quotas": [], "scores": [ { "id": "163140-7bbd-ea8b-d8a-2b4ca2b5572", "score": "0", "value": "eeac105-0d43-3e6d-b24a-7807ed84bd6" }, { "id": "4384ef8-006e-def8-c11-1d7e5b87fb", "score": "0", "value": null } ], "rubricId": null, "clusterScoring": null, "rubricViewedBy": null, "allSelectedZero": null, "rubricDirections": "" }, "content_codes": [ "ELA.6.C1" ], "media_library": [], "revision_text": null, "task_user_ids": null, "item_type_code": "MDB", "item_type_name": "Multiple Drop Bucket", "scoring_needed": true, "workflow_tasks": null, "workflow_users": null, "attributes_list": [ { "enemies": null, "friends": null, "group_info": { "grade_id": 149, "content_area_id": 85, "framework_type_ids": [ 411 ] }, "item_usage": 39, "content_codes": [ { "id": 22836, "selection": true, "is_primary": true, "is_secondary": false, "framework_type_id": 411 } ], "testing_program": [ 83 ], "cognitive_category": 354, "cognitive_taxonomy": 282, "estimate_difficulty": 386, "multiple_primary_content_code_needed": [ { "value": true, "framework_type_ids": [] } ] } ], "cluster_scoring": null, "content_area_id": 85, "created_user_id": 2, "framework_types": [ "SBAC-ELA" ], "previous_source": null, "testing_program": "Practice", "variant_type_id": null, "workflow_status": null, "content_code_ids": [ 22836 ], "item_status_code": "final", "item_status_name": "Final", "workflow_task_id": null, "workflow_user_id": null, "created_user_name": "User Two", "is_latest_version": true, "readable_response": null, "scoring_method_id": 62, "accessibility_json": null, "framework_type_ids": [ 411 ], "testing_program_id": "83", "workflow_task_skip": null, "scoring_method_code": "correct_only", "workflow_content_id": null, "workflow_process_id": null, "accessibility_details": null, "assessment_program_id": 15009, "workflow_content_type": null, "workflow_graphic_path": null, "workflow_process_name": null, "assessment_program_ids": null, "assessment_program_code": null, "item_type_category_code": "question", "item_type_category_name": "Question", "workflow_content_type_id": null, "workflow_content_user_ids": null, "workflow_process_description": null }; var myCopy = null; function recursiveDeepCopy(o) { var newO, i; if (typeof o !== 'object') { return o; } if (!o) { return o; } if ('[object Array]' === Object.prototype.toString.apply(o)) { newO = []; for (i = 0; i < o.length; i += 1) { newO[i] = recursiveDeepCopy(o[i]); } return newO; } newO = {}; for (i in o) { if (o.hasOwnProperty(i)) { newO[i] = recursiveDeepCopy(o[i]); } } return newO; }
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Native structuredClone
myCopy = structuredClone(MyObject);
recursiveDeepCopy
myCopy = recursiveDeepCopy(MyObject);
Json Clone
myCopy = JSON.parse(JSON.stringify(MyObject));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
recursiveDeepCopy
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):
It seems like you're looking for the best cloning method among `_.cloneDeep`, `structuredClone`, `recursiveDeepCopy`, and `JSON.parse(JSON.stringify)`. Let's analyze each option: 1. **`.cloneDeep` (Lodash)**: This function is designed to create a deep copy of an object, including all its nested objects. It recursively traverses the original object and creates new copies of all the properties, ensuring that even deeply nested structures are preserved. 2. **`.structuredClone` (Native)**: This method is part of the Web Assembly (WASM) module and provides a way to create a deep copy of an object while preserving the relationships between objects. It's generally more efficient than other cloning methods but may not be as widely supported yet, especially for older browsers. 3. **`.recursiveDeepCopy`**: This function is designed by you to recursively traverse the original object and create new copies of all its properties. It handles arrays and nested objects accurately, ensuring a deep copy is made. 4. **`.JSON.parse(JSON.stringify())`**: Although this method seems simple, it's not always reliable for complex data structures with circular references. When the parser encounters a circular reference, it throws an error. This method doesn't handle such cases effectively, especially when dealing with nested objects or arrays that contain each other. Given these characteristics, let's compare their performance in your benchmarking scenario: **Benchmark Results** | Test Name | Executions Per Second | | --- | --- | | Json Clone | 10708.4638671875 | | recursiveDeepCopy | 13153.9931640625 | | Native structuredClone | 17992.376953125 | | Lodash cloneDeep | 19110.388671875 | Based on the benchmark results, it appears that `recursiveDeepCopy` outperforms all other options in terms of executions per second. Here's an example implementation for the chosen cloning method: ```javascript function recursiveDeepCopy(o) { if (typeof o !== 'object') { return o; } if (!o) { return o; } if ('[object Array]' === Object.prototype.toString.apply(o)) { return []; } const newO = {}; for (const i in o) { if (o.hasOwnProperty(i)) { newO[i] = recursiveDeepCopy(o[i]); } } return newO; } ``` Note that this implementation handles arrays correctly by initializing the `newO` array and iterating over its elements using a `for...in` loop, ensuring accurate copying of nested objects.
Related benchmarks:
Lodash groupBy vs JS reduce
Lodash uniqBy vs Reduce uniqBy
lodash groupBy vs Array.reduce 100k corrected
lodash groupBy vs Array.reduce 100
lodash groupBy vs Array.reduce 100k with array push
Comments
Confirm delete:
Do you really want to delete benchmark?