Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash latest clonedeep vs json.parse(stringify()) vs recursivecopy
(version: 0)
Comparing performance of:
Lodash CloneDeep vs Json Clone vs recursiveDeepCopy
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
var MyObject = { "test": [ { "_id": "65264d6b8866d9c1f15b2bb7", "index": 0, "guid": "a23ff2c7-a512-41fa-8c02-9cb3fcc90860", "isActive": false, "balance": "$3,060.43", "picture": "http://placehold.it/32x32", "age": 36, "eyeColor": "blue", "name": "Marla Boyer", "gender": "female", "company": "UXMOX", "email": "marlaboyer@uxmox.com", "phone": "+1 (910) 510-3561", "address": "602 Hornell Loop, Accoville, Massachusetts, 4738", "about": "Id irure velit magna tempor aliquip culpa anim aute aliquip do consequat. Aliqua laborum est eiusmod culpa magna cillum fugiat reprehenderit fugiat. Quis sit esse aute nulla excepteur tempor eu ullamco reprehenderit. Ut veniam do ad quis aute nulla occaecat. Id culpa dolore eiusmod ea deserunt esse consectetur magna nulla. Do nulla dolor deserunt minim enim veniam anim eiusmod cillum ut minim laboris excepteur. Duis exercitation labore eiusmod cillum tempor reprehenderit aute consequat.\r\n", "registered": "2021-05-28T08:23:11 -08:00", "latitude": -87.278548, "longitude": 88.4891, "tags": [ "ea", "sint", "ut", "dolor", "eu", "cupidatat", "excepteur" ], "friends": [ { "id": 0, "name": "Rachelle Moses" }, { "id": 1, "name": "Carey Rosario" }, { "id": 2, "name": "Jeannette Carver" } ], "greeting": "Hello, Marla Boyer! You have 7 unread messages.", "favoriteFruit": "apple" }, { "_id": "65264d6bd49aa5567ab4b7b3", "index": 1, "guid": "5c8d6d07-c772-4ad3-9f95-c630f0bb2d88", "isActive": true, "balance": "$1,797.57", "picture": "http://placehold.it/32x32", "age": 29, "eyeColor": "brown", "name": "Pratt Callahan", "gender": "male", "company": "EARGO", "email": "prattcallahan@eargo.com", "phone": "+1 (900) 421-2558", "address": "564 Milton Street, Smock, Wyoming, 7185", "about": "Ad officia aliquip sit minim exercitation culpa reprehenderit non dolore. Lorem tempor dolore qui laborum sit nulla esse dolor proident tempor pariatur laborum. Sint do dolore ea pariatur ea non.\r\n", "registered": "2022-12-30T10:15:39 -08:00", "latitude": 16.169188, "longitude": 110.862123, "tags": [ "deserunt", "laborum", "Lorem", "minim", "esse", "Lorem", "adipisicing" ], "friends": [ { "id": 0, "name": "Wilkins Mack" }, { "id": 1, "name": "Gail Blackburn" }, { "id": 2, "name": "Castillo Franks" } ], "greeting": "Hello, Pratt Callahan! You have 1 unread messages.", "favoriteFruit": "apple" }, { "_id": "65264d6bcbf167adbb5a36f8", "index": 2, "guid": "1722f700-5ca2-4aa2-b6d2-828e821728f3", "isActive": true, "balance": "$3,336.85", "picture": "http://placehold.it/32x32", "age": 40, "eyeColor": "green", "name": "Adams Terrell", "gender": "male", "company": "CRUSTATIA", "email": "adamsterrell@crustatia.com", "phone": "+1 (896) 508-2735", "address": "124 Hamilton Avenue, Madrid, South Dakota, 2017", "about": "Officia aliqua commodo dolor reprehenderit laboris eu pariatur nulla non excepteur. Tempor tempor tempor exercitation esse. Lorem dolore cillum minim aliqua occaecat proident aliquip adipisicing id sint. Laborum duis et consequat et ut. Adipisicing ut culpa eiusmod ea. Consequat elit qui veniam non commodo anim voluptate laboris mollit incididunt magna cillum. Anim do tempor ut exercitation eiusmod exercitation in fugiat.\r\n", "registered": "2022-01-11T08:50:24 -08:00", "latitude": -14.747563, "longitude": -46.862488, "tags": [ "consequat", "aliquip", "deserunt", "amet", "amet", "dolor", "irure" ], "friends": [ { "id": 0, "name": "Rose Matthews" }, { "id": 1, "name": "Sheila Benjamin" }, { "id": 2, "name": "Charlene Newman" } ], "greeting": "Hello, Adams Terrell! You have 10 unread messages.", "favoriteFruit": "banana" }, { "_id": "65264d6b238f156f4f3a04e3", "index": 3, "guid": "0dbc7b93-16e4-480d-b81f-bad0eb1a95b5", "isActive": false, "balance": "$2,424.13", "picture": "http://placehold.it/32x32", "age": 23, "eyeColor": "blue", "name": "Taylor Maldonado", "gender": "male", "company": "ZIZZLE", "email": "taylormaldonado@zizzle.com", "phone": "+1 (872) 590-3482", "address": "538 Anchorage Place, Dorneyville, Illinois, 6550", "about": "Fugiat ad minim sit ex. Commodo enim cillum enim consectetur exercitation excepteur aliqua irure cupidatat consequat cupidatat dolor irure. Sint officia adipisicing nisi dolore minim. Laboris excepteur minim esse dolor irure consequat esse incididunt deserunt pariatur labore exercitation pariatur ipsum. Sit fugiat ad irure ipsum elit id officia exercitation. Ex dolore fugiat sint mollit quis sint commodo irure quis pariatur exercitation.\r\n", "registered": "2018-06-26T04:06:21 -08:00", "latitude": -2.888858, "longitude": -73.705591, "tags": [ "nostrud", "voluptate", "velit", "commodo", "ad", "ex", "duis" ], "friends": [ { "id": 0, "name": "Williamson Whitney" }, { "id": 1, "name": "Janine Guy" }, { "id": 2, "name": "Huffman Wells" } ], "greeting": "Hello, Taylor Maldonado! You have 3 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "65264d6b46db9d1ef62467fb", "index": 4, "guid": "c35b4d7e-78ad-4d83-869c-317d33b6bb5e", "isActive": true, "balance": "$3,225.21", "picture": "http://placehold.it/32x32", "age": 25, "eyeColor": "green", "name": "Mccoy Wolfe", "gender": "male", "company": "BYTREX", "email": "mccoywolfe@bytrex.com", "phone": "+1 (856) 584-3648", "address": "300 Calder Place, Odessa, Texas, 923", "about": "Ipsum amet minim esse pariatur dolore eu. Nisi eiusmod et eiusmod dolor culpa. Reprehenderit in duis nisi nostrud pariatur veniam quis occaecat nisi ut aliquip cupidatat duis.\r\n", "registered": "2022-12-20T01:14:17 -08:00", "latitude": 36.777164, "longitude": 84.712524, "tags": [ "nostrud", "esse", "excepteur", "reprehenderit", "cupidatat", "occaecat", "amet" ], "friends": [ { "id": 0, "name": "Hall Mercado" }, { "id": 1, "name": "Cortez Stevens" }, { "id": 2, "name": "Santiago Barron" } ], "greeting": "Hello, Mccoy Wolfe! You have 6 unread messages.", "favoriteFruit": "banana" }, { "_id": "65264d6b2be6035cb0f7674d", "index": 5, "guid": "4e6f9ca9-6ad2-4a10-aa2b-2cd18e889016", "isActive": true, "balance": "$1,090.00", "picture": "http://placehold.it/32x32", "age": 35, "eyeColor": "green", "name": "Pearl Tyler", "gender": "female", "company": "AQUAZURE", "email": "pearltyler@aquazure.com", "phone": "+1 (836) 494-3045", "address": "467 Miller Place, Linganore, West Virginia, 3419", "about": "Et enim id est in voluptate eu eu dolor ut anim excepteur consectetur laborum dolor. Cillum eiusmod aute ut commodo excepteur culpa velit Lorem sit exercitation. Magna consectetur labore qui consequat sit cillum culpa occaecat eiusmod magna aute cillum laborum enim.\r\n", "registered": "2019-01-28T01:24:06 -08:00", "latitude": -48.96066, "longitude": 74.852688, "tags": [ "culpa", "excepteur", "cupidatat", "occaecat", "commodo", "aliqua", "sint" ], "friends": [ { "id": 0, "name": "Jessie George" }, { "id": 1, "name": "Barnes Graham" }, { "id": 2, "name": "Patsy Beck" } ], "greeting": "Hello, Pearl Tyler! You have 6 unread messages.", "favoriteFruit": "apple" } ] }; 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);
Json Clone
myCopy = JSON.parse(JSON.stringify(MyObject));
recursiveDeepCopy
myCopy = recursiveDeepCopy(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash CloneDeep
Json Clone
recursiveDeepCopy
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):
To answer your question, I'll need to analyze the provided code snippets and their corresponding benchmark results. The original JSON object: ```json { "MyObject": { "registered": "2019-01-28T01:24:06 -08:00", "latitude": -48.96066, "longitude": 74.852688, "tags": [ "culpa", "excepteur", "cupidatat", "occaecat", "commodo", "aliqua", "sint" ], "friends": [ { "id": 0, "name": "Jessie George" }, { "id": 1, "name": "Barnes Graham" }, { "id": 2, "name": "Patsy Beck" } ], "greeting": "Hello, Pearl Tyler! You have 6 unread messages.", "favoriteFruit": "apple" } } ``` The individual test cases: ```javascript [ { "Benchmark Definition": "myCopy = _.cloneDeep(MyObject);", "Test Name": "Lodash CloneDeep" }, { "Benchmark Definition": "myCopy = JSON.parse(JSON.stringify(MyObject));", "Test Name": "Json Clone" }, { "Benchmark Definition": "myCopy = recursiveDeepCopy(MyObject);", "Test Name": "recursiveDeepCopy" } ] ``` The latest benchmark result: ```json [ { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", "Browser": "Chrome 117", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 64967.4453125, "TestName": "recursiveDeepCopy" }, { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", "Browser": "Chrome 117", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 52757.0390625, "TestName": "Lodash CloneDeep" }, { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", "Browser": "Chrome 117", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 49464.23828125, "TestName": "Json Clone" } ] ``` After analyzing the code snippets and benchmark results, I can provide a brief comparison of their performance: 1. **recursiveDeepCopy**: This custom implementation seems to be the fastest, with an average execution speed of approximately 64967.4453125 executions per second. 2. **Lodash CloneDeep**: The Lodash `cloneDeep` function has an average execution speed of around 52757.0390625 executions per second, which is about 19% slower than the custom implementation. 3. **Json Clone**: Using `JSON.parse(JSON.stringify(MyObject))` results in the slowest performance, with an average execution speed of approximately 49464.23828125 executions per second, which is around 23% slower than the custom implementation. Keep in mind that these results are based on a single benchmark and may not be representative of all scenarios or environments. Please let me know if you have any further questions!
Related benchmarks:
Lodash cloneDeep vs JSON Clone (Large Object 2)
Lodash cloneDeep vs JSON Clone with Array
cloneDeep vs JSON stringify + parse (long arr)
Lodash(v4.17.21) cloneDeep vs JSON Clone Larger object
Comments
Confirm delete:
Do you really want to delete benchmark?