Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone big 123123123
(version: 1)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Native structuredClone vs lodash
Created:
8 months 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 MyObjectSmall = { 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...' }, foo: [{ "_id": "68b0326cf33520d80ef8ff65", "index": 0, "guid": "499fa4e8-95f3-4dca-8a9e-ac8cf7a12cff", "isActive": false, "balance": "$1,438.51", "picture": "http://placehold.it/32x32", "age": 32, "eyeColor": "green", "name": "Christensen Sargent", "gender": "male", "company": "CONFRENZY", "email": "christensensargent@confrenzy.com", "phone": "+1 (817) 463-2462", "address": "955 Pine Street, Wattsville, Northern Mariana Islands, 456", "about": "Qui ad do cillum ea enim elit id non ut pariatur. Pariatur et incididunt pariatur amet tempor in adipisicing proident. Proident Lorem ipsum consectetur elit do labore labore eiusmod labore do.\r\n", "registered": "2017-11-10T02:03:58 -02:00", "latitude": 35.777275, "longitude": -88.696162, "tags": [ "ad", "ut", "sint", "id", "velit", "ex", "commodo" ], "friends": [{ "id": 0, "name": "Andrea Hays" }, { "id": 1, "name": "Brandy Castro" }, { "id": 2, "name": "Katelyn King" } ], "greeting": "Hello, Christensen Sargent! You have 2 unread messages.", "favoriteFruit": "banana" }, { "_id": "68b0326c1aa7a2aaada5408c", "index": 1, "guid": "da32677c-f2ef-47b0-8a2d-c1785d989f12", "isActive": false, "balance": "$2,350.33", "picture": "http://placehold.it/32x32", "age": 27, "eyeColor": "brown", "name": "Larson Holloway", "gender": "male", "company": "ZENTIX", "email": "larsonholloway@zentix.com", "phone": "+1 (937) 442-3327", "address": "400 Cozine Avenue, Shawmut, Guam, 3007", "about": "Fugiat occaecat cillum sint dolor irure officia mollit in commodo veniam ipsum ullamco. Cupidatat aliquip consectetur anim elit ipsum. Tempor consequat duis fugiat nostrud.\r\n", "registered": "2023-05-01T11:03:37 -03:00", "latitude": 77.678245, "longitude": 107.480104, "tags": [ "eiusmod", "et", "proident", "excepteur", "do", "quis", "esse" ], "friends": [{ "id": 0, "name": "Boyer Jackson" }, { "id": 1, "name": "Alissa Kaufman" }, { "id": 2, "name": "Velazquez Avery" } ], "greeting": "Hello, Larson Holloway! You have 10 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "68b0326c0c21a31abf3917b7", "index": 2, "guid": "c7cd686f-342c-4073-8250-7695bc552f9b", "isActive": true, "balance": "$1,141.79", "picture": "http://placehold.it/32x32", "age": 40, "eyeColor": "green", "name": "Buckley Bonner", "gender": "male", "company": "OPTICON", "email": "buckleybonner@opticon.com", "phone": "+1 (924) 528-3941", "address": "130 Judge Street, Makena, Mississippi, 209", "about": "Dolor pariatur non deserunt dolore voluptate eiusmod velit. Deserunt consequat adipisicing veniam occaecat eiusmod ipsum ad fugiat laboris sunt incididunt fugiat labore. Ullamco et irure dolore do dolor. Magna mollit ipsum eu do proident tempor cupidatat eiusmod dolore ad Lorem. Aliquip eu ad excepteur aliqua incididunt excepteur deserunt eu mollit occaecat culpa ex cupidatat dolore.\r\n", "registered": "2018-01-27T05:07:16 -02:00", "latitude": -81.815164, "longitude": -32.535058, "tags": [ "fugiat", "duis", "id", "deserunt", "ex", "sunt", "ullamco" ], "friends": [{ "id": 0, "name": "Sheppard Britt" }, { "id": 1, "name": "Miriam Nielsen" }, { "id": 2, "name": "Ruiz Duran" } ], "greeting": "Hello, Buckley Bonner! You have 10 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "68b0326c0abc9e52ed673a8f", "index": 3, "guid": "0af18da5-8c19-468c-97c4-e2d78551577b", "isActive": false, "balance": "$2,690.62", "picture": "http://placehold.it/32x32", "age": 36, "eyeColor": "blue", "name": "Carey Palmer", "gender": "male", "company": "ZBOO", "email": "careypalmer@zboo.com", "phone": "+1 (806) 432-2220", "address": "418 Nixon Court, Datil, Maine, 3784", "about": "Voluptate tempor Lorem sint dolore consequat eiusmod cupidatat et consequat. Do aliquip commodo aute sunt tempor fugiat eu id aute ut et sit nulla cillum. Nisi esse ad id adipisicing id in incididunt voluptate enim et cillum elit sit. Sunt nulla quis dolore reprehenderit proident minim. Enim Lorem adipisicing est nulla eu. Et adipisicing dolor exercitation reprehenderit aute consectetur ullamco id qui tempor cillum in dolor incididunt.\r\n", "registered": "2025-08-22T12:14:59 -03:00", "latitude": -44.825202, "longitude": -60.665693, "tags": [ "pariatur", "nisi", "sunt", "excepteur", "ea", "anim", "adipisicing" ], "friends": [{ "id": 0, "name": "Eunice Sweet" }, { "id": 1, "name": "Blanca Patterson" }, { "id": 2, "name": "Sargent Becker" } ], "greeting": "Hello, Carey Palmer! You have 10 unread messages.", "favoriteFruit": "apple" }, { "_id": "68b0326cb74cd88acc7e801d", "index": 4, "guid": "03f371f8-2c10-41b5-9bcd-cb6bb2adf893", "isActive": true, "balance": "$1,535.19", "picture": "http://placehold.it/32x32", "age": 30, "eyeColor": "blue", "name": "Stella Porter", "gender": "female", "company": "GEEKFARM", "email": "stellaporter@geekfarm.com", "phone": "+1 (819) 419-3415", "address": "398 Greene Avenue, Stewartville, Virginia, 7803", "about": "Laboris est ullamco voluptate dolor cupidatat aliqua in. Sit consequat exercitation ut fugiat enim reprehenderit est eiusmod aliquip voluptate deserunt nisi tempor irure. Nostrud deserunt magna ad incididunt elit. Excepteur tempor aliqua id consectetur culpa fugiat magna ipsum nisi. Occaecat esse ex ipsum eu pariatur dolor proident fugiat officia. Aliquip culpa voluptate excepteur ex exercitation est elit pariatur duis ea. Labore esse fugiat incididunt dolore laborum aliqua fugiat laborum anim minim sint laboris cillum.\r\n", "registered": "2017-11-18T08:09:05 -02:00", "latitude": -54.63794, "longitude": -140.142226, "tags": [ "aute", "exercitation", "non", "dolore", "mollit", "excepteur", "aliquip" ], "friends": [{ "id": 0, "name": "Nora Clements" }, { "id": 1, "name": "Sofia Neal" }, { "id": 2, "name": "Marlene Cash" } ], "greeting": "Hello, Stella Porter! You have 8 unread messages.", "favoriteFruit": "apple" } ], boo: [{ "_id": "68b0326cf33520d80ef8ff65", "index": 0, "guid": "499fa4e8-95f3-4dca-8a9e-ac8cf7a12cff", "isActive": false, "balance": "$1,438.51", "picture": "http://placehold.it/32x32", "age": 32, "eyeColor": "green", "name": "Christensen Sargent", "gender": "male", "company": "CONFRENZY", "email": "christensensargent@confrenzy.com", "phone": "+1 (817) 463-2462", "address": "955 Pine Street, Wattsville, Northern Mariana Islands, 456", "about": "Qui ad do cillum ea enim elit id non ut pariatur. Pariatur et incididunt pariatur amet tempor in adipisicing proident. Proident Lorem ipsum consectetur elit do labore labore eiusmod labore do.\r\n", "registered": "2017-11-10T02:03:58 -02:00", "latitude": 35.777275, "longitude": -88.696162, "tags": [ "ad", "ut", "sint", "id", "velit", "ex", "commodo" ], "friends": [{ "id": 0, "name": "Andrea Hays" }, { "id": 1, "name": "Brandy Castro" }, { "id": 2, "name": "Katelyn King" } ], "greeting": "Hello, Christensen Sargent! You have 2 unread messages.", "favoriteFruit": "banana" }, { "_id": "68b0326c1aa7a2aaada5408c", "index": 1, "guid": "da32677c-f2ef-47b0-8a2d-c1785d989f12", "isActive": false, "balance": "$2,350.33", "picture": "http://placehold.it/32x32", "age": 27, "eyeColor": "brown", "name": "Larson Holloway", "gender": "male", "company": "ZENTIX", "email": "larsonholloway@zentix.com", "phone": "+1 (937) 442-3327", "address": "400 Cozine Avenue, Shawmut, Guam, 3007", "about": "Fugiat occaecat cillum sint dolor irure officia mollit in commodo veniam ipsum ullamco. Cupidatat aliquip consectetur anim elit ipsum. Tempor consequat duis fugiat nostrud.\r\n", "registered": "2023-05-01T11:03:37 -03:00", "latitude": 77.678245, "longitude": 107.480104, "tags": [ "eiusmod", "et", "proident", "excepteur", "do", "quis", "esse" ], "friends": [{ "id": 0, "name": "Boyer Jackson" }, { "id": 1, "name": "Alissa Kaufman" }, { "id": 2, "name": "Velazquez Avery" } ], "greeting": "Hello, Larson Holloway! You have 10 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "68b0326c0c21a31abf3917b7", "index": 2, "guid": "c7cd686f-342c-4073-8250-7695bc552f9b", "isActive": true, "balance": "$1,141.79", "picture": "http://placehold.it/32x32", "age": 40, "eyeColor": "green", "name": "Buckley Bonner", "gender": "male", "company": "OPTICON", "email": "buckleybonner@opticon.com", "phone": "+1 (924) 528-3941", "address": "130 Judge Street, Makena, Mississippi, 209", "about": "Dolor pariatur non deserunt dolore voluptate eiusmod velit. Deserunt consequat adipisicing veniam occaecat eiusmod ipsum ad fugiat laboris sunt incididunt fugiat labore. Ullamco et irure dolore do dolor. Magna mollit ipsum eu do proident tempor cupidatat eiusmod dolore ad Lorem. Aliquip eu ad excepteur aliqua incididunt excepteur deserunt eu mollit occaecat culpa ex cupidatat dolore.\r\n", "registered": "2018-01-27T05:07:16 -02:00", "latitude": -81.815164, "longitude": -32.535058, "tags": [ "fugiat", "duis", "id", "deserunt", "ex", "sunt", "ullamco" ], "friends": [{ "id": 0, "name": "Sheppard Britt" }, { "id": 1, "name": "Miriam Nielsen" }, { "id": 2, "name": "Ruiz Duran" } ], "greeting": "Hello, Buckley Bonner! You have 10 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "68b0326c0abc9e52ed673a8f", "index": 3, "guid": "0af18da5-8c19-468c-97c4-e2d78551577b", "isActive": false, "balance": "$2,690.62", "picture": "http://placehold.it/32x32", "age": 36, "eyeColor": "blue", "name": "Carey Palmer", "gender": "male", "company": "ZBOO", "email": "careypalmer@zboo.com", "phone": "+1 (806) 432-2220", "address": "418 Nixon Court, Datil, Maine, 3784", "about": "Voluptate tempor Lorem sint dolore consequat eiusmod cupidatat et consequat. Do aliquip commodo aute sunt tempor fugiat eu id aute ut et sit nulla cillum. Nisi esse ad id adipisicing id in incididunt voluptate enim et cillum elit sit. Sunt nulla quis dolore reprehenderit proident minim. Enim Lorem adipisicing est nulla eu. Et adipisicing dolor exercitation reprehenderit aute consectetur ullamco id qui tempor cillum in dolor incididunt.\r\n", "registered": "2025-08-22T12:14:59 -03:00", "latitude": -44.825202, "longitude": -60.665693, "tags": [ "pariatur", "nisi", "sunt", "excepteur", "ea", "anim", "adipisicing" ], "friends": [{ "id": 0, "name": "Eunice Sweet" }, { "id": 1, "name": "Blanca Patterson" }, { "id": 2, "name": "Sargent Becker" } ], "greeting": "Hello, Carey Palmer! You have 10 unread messages.", "favoriteFruit": "apple" }, { "_id": "68b0326cb74cd88acc7e801d", "index": 4, "guid": "03f371f8-2c10-41b5-9bcd-cb6bb2adf893", "isActive": true, "balance": "$1,535.19", "picture": "http://placehold.it/32x32", "age": 30, "eyeColor": "blue", "name": "Stella Porter", "gender": "female", "company": "GEEKFARM", "email": "stellaporter@geekfarm.com", "phone": "+1 (819) 419-3415", "address": "398 Greene Avenue, Stewartville, Virginia, 7803", "about": "Laboris est ullamco voluptate dolor cupidatat aliqua in. Sit consequat exercitation ut fugiat enim reprehenderit est eiusmod aliquip voluptate deserunt nisi tempor irure. Nostrud deserunt magna ad incididunt elit. Excepteur tempor aliqua id consectetur culpa fugiat magna ipsum nisi. Occaecat esse ex ipsum eu pariatur dolor proident fugiat officia. Aliquip culpa voluptate excepteur ex exercitation est elit pariatur duis ea. Labore esse fugiat incididunt dolore laborum aliqua fugiat laborum anim minim sint laboris cillum.\r\n", "registered": "2017-11-18T08:09:05 -02:00", "latitude": -54.63794, "longitude": -140.142226, "tags": [ "aute", "exercitation", "non", "dolore", "mollit", "excepteur", "aliquip" ], "friends": [{ "id": 0, "name": "Nora Clements" }, { "id": 1, "name": "Sofia Neal" }, { "id": 2, "name": "Marlene Cash" } ], "greeting": "Hello, Stella Porter! You have 8 unread messages.", "favoriteFruit": "apple" } ] }; var myCopy = null; var MyObject = Array(100).fill(MyObjectSmall);
Tests:
Native structuredClone
myCopy = structuredClone(MyObject);
lodash
myCopy = _.cloneDeep(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native structuredClone
lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native structuredClone
31773.0 Ops/sec
lodash
21951.3 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated 8 months ago):
The benchmark defined in the provided JSON compares two methods for creating deep copies of JavaScript objects: the native `structuredClone` method and the `cloneDeep` method from the Lodash library. ### Benchmark Comparison 1. **Native structuredClone**: - **Description**: The `structuredClone` function is a built-in JavaScript method that allows for creating a deep copy of a JavaScript object or array. It handles a wide variety of built-in types, including `Date`, `Map`, `Set`, `ArrayBuffer`, and more, all while preserving their properties and state. - **Pros**: - It's a native function, meaning it benefits from being optimized by the JavaScript engine, generally yielding higher performance. - Handles complex data structures (like `Date` and `Map`) and circular references natively. - **Cons**: - Limited to JavaScript’s built-in types; custom objects may not be cloned as expected. - Some types (such as functions, DOM nodes, and others) are not supported. 2. **Lodash cloneDeep**: - **Description**: Lodash is a popular utility library that provides various functions for common programming tasks. Its `cloneDeep` function allows for creating deep copies of objects and arrays, handling nested structures and circular references. - **Pros**: - More flexible for cloning JavaScript objects, including user-defined prototype objects and other non-standard data types. - Intuitive and has a consistent API along with other Lodash functions. - **Cons**: - Being a library function, it might have additional overhead compared to native functions, potentially making it slower. - Includes more code by default, which might increase bundle size if not tree-shaken properly. ### Benchmark Results The benchmark results indicate the performance of the two methods under similar conditions: - **Native structuredClone**: 31,773 executions per second. - **Lodash cloneDeep**: 21,951 executions per second. This shows that the native `structuredClone` method outperformed the Lodash `cloneDeep` in this specific benchmark scenario, highlighting the advantage of using optimized native functions when available. ### Considerations for Developers - If performance is crucial and you’re handling standard JavaScript objects, opting for `structuredClone` is recommended due to higher speed. - For more complex scenarios where non-standard objects or specific data types are involved, or if you are already using Lodash in your project, `cloneDeep` may be more appropriate due to its flexibility. - It's essential to consider whether a library function like Lodash is necessary, as using native alternatives can reduce dependencies and improve performance, especially in performance-sensitive applications. ### Other Alternatives Beyond `structuredClone` and `Lodash.cloneDeep`, other alternatives for deep cloning include: - **JSON Methods**: `JSON.parse(JSON.stringify(obj))` is a common pattern but has significant limitations: - Does not handle functions, dates, undefined, or special objects like `Map` and `Set`. - **Manual Cloning**: Custom cloning functions can also be written for specific object types, but this can lead to maintenance challenges. - **Immutable.js**: Provides a more structured way to manage data with built-in functions for data immutability and copying. Choosing the appropriate method largely depends on the specific requirements of your application, including the object's complexity, required performance, and available libraries.
Related benchmarks:
Lodash cloneDeep vs structuredClone vs JSON Parse
Lodash cloneDeep vs structuredClone 222222
Lodash cloneDeep vs structuredClone2
Lodash cloneDeep vs structuredClone vs naive JSON.stringify
Lodash cloneDeep vs structuredClone vs JSON-JSON
Lodash cloneDeep vs structuredClone vs JSON Parse (Big Object)
Lodash cloneDeep vs structuredClone 2asdasdas
Lodash cloneDeep vs structuredClone 2222
Lodash cloneDeep vs structuredClone 22222
Comments
Confirm delete:
Do you really want to delete benchmark?