Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Adam Lodash cloneDeep vs structuredClone
(version: 1)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone
Created:
one year 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": 3, "name": "TEST_PLANOGRAM", "holdingAreaSkus": [], "holdingAreaFurniture": [], "regions": ["UK"], "bays": [ { "signageText": "hello", "width": 1, "depth": 0.37, "fixtureId": 3, "fixture": { "height": 2.085, "wallThickness": null, "topBarHeight": null, "topBarDepth": null, "startNotchOffset": null, "sidewallsWidth": null, "kickplateHeight": 0.14, "notchSpacing": 0.0491, "maxNotch": 34, "readOnlyBaseFurniture": { "id": 1, "name": "FixtureTest", "shelfThickness": 0.015, "defaultShelfDepth": 0.35 } }, "shelves": [ { "alignment": "LTR", "thickness": 0.015, "width": 1, "height": 0, "depth": 0.37, "products": [ { "type": "ON_SHELF_FURNITURE", "productId": "Basket_1", "width": 0.3, "height": 0.12, "depth": 0.3, "furnitureType": "BASKET", "text": "", "furnitureContent": [ { "alignment": "CENTRE", "width": 0.3, "height": 0.002, "depth": 0.3, "products": [ { "productId": 36085, "vertical": 1, "horizontal": 1, "width": 0.058, "height": 0.1, "depth": 0.058, "depthFacings": 5, "crush": null, "rotation": "FRONT_0", "rotations": [], "type": "SKU", "placementId": "c68460c8-d933-40b6-9ed1-5b506b5e71cf" } ], "coordinates": null, "placementId": "a35e683a-24ff-4177-a22a-84eb1e976201" } ], "placementId": "ae7a6f65-f4b7-4556-ac18-e64f9ad65f01" }, { "type": "ON_SHELF_FURNITURE", "productId": "DS_1", "width": 0.3, "height": 0.4, "depth": 0.3, "furnitureType": "DISPLAY_STAND", "text": "", "furnitureContent": [ { "alignment": "CENTRE", "width": 0.3, "height": 0, "depth": 0.3, "products": [ { "productId": 36085, "vertical": 1, "horizontal": 1, "width": 0.058, "height": 0.1, "depth": 0.058, "depthFacings": 5, "crush": null, "rotation": "FRONT_0", "rotations": [], "type": "SKU", "placementId": "52a67190-cd42-415e-bef0-6fb79b7e2cbd" } ], "coordinates": null, "placementId": "99c108de-416d-428a-acdd-30de729ac5f5" }, { "alignment": "LTR", "width": 0.3, "height": 0.15, "depth": 0.25, "products": [ { "productId": 77130, "vertical": 1, "horizontal": 1, "width": 0.058, "height": 0.1, "depth": 0.058, "depthFacings": 4, "crush": null, "rotation": "FRONT_0", "rotations": [], "type": "SKU", "placementId": "ebeab366-f199-4746-8606-eaf874e302ea" } ], "coordinates": null, "placementId": "820e9448-635a-4adc-bb7d-1ed115169c24" } ], "placementId": "d01ff40d-b814-4f27-ba85-c7014c62127c" }, { "type": "ON_SHELF_FURNITURE", "productId": "STAND_1", "width": 0.3, "height": 0.15, "depth": 0.3, "furnitureType": "STAND", "text": "", "furnitureContent": [ { "alignment": "CENTRE", "width": 0.3, "height": 0.3, "depth": 0.3, "products": [ { "productId": 77130, "vertical": 1, "horizontal": 1, "width": 0.058, "height": 0.11, "depth": 0.058, "depthFacings": 5, "crush": null, "rotation": "FRONT_0", "rotations": [], "type": "SKU", "placementId": "1dd681b5-f5b9-4e3e-bc7d-b376a3f1be39" } ], "coordinates": null, "placementId": "00d7fb28-989a-4555-bb95-5aa912f55ffc" } ], "placementId": "a29028d2-8a53-4fb3-8c8e-b9b248a8c434" } ], "placementId": "5b7b139a-b4bb-4231-be08-e162f9131a0a" }, { "alignment": "EVEN", "thickness": 0.015, "width": 1, "height": 0.4418, "depth": 0.37, "products": [ { "type": "ON_SHELF_FURNITURE", "productId": "STRUT_1", "width": 0.2, "height": 0.3, "depth": 0.03, "furnitureType": "STRUT", "text": "STRUT 1", "url": "", "furnitureContent": [], "placementId": "15605f89-582c-4a31-806b-f8adb31af30d" }, { "productId": 36085, "vertical": 1, "horizontal": 1, "width": 0.3, "height": 0.3, "depth": 0.058, "depthFacings": 6, "crush": null, "rotation": "LEFT_0", "rotations": [], "type": "SKU", "placementId": "4b90679b-e814-4df6-985c-0642034e9dd2" } ], "coordinates": null, "placementId": "9f947ec3-feaf-483e-a8e8-7eab4634c46c" }, { "alignment": "LTR", "thickness": 0.015, "width": 1, "height": 0.982, "depth": 0.37, "products": [ { "type": "ON_SHELF_FURNITURE", "productId": "LB_1m", "width": 1, "height": 0.25, "depth": 0.2, "furnitureType": "LIGHT_BOX", "text": "", "url": "", "furnitureContent": [], "placementId": "101c6068-8551-4904-8153-3fa4dba7cfe2" } ], "coordinates": null, "placementId": "a9c037c9-4a67-46f6-ae2b-bd09ede5b27b" }, { "alignment": "LTR", "thickness": 0.015, "width": 1, "height": 1.423, "depth": 0.37, "products": [ { "type": "ON_SHELF_FURNITURE", "productId": "HERO_1m", "width": 1, "height": 0.45, "depth": 0.13, "furnitureType": "HERO_BOX", "text": "", "url": "", "furnitureContent": [ { "alignment": "CENTRE", "width": 0.94, "height": 0.07, "depth": 0.13, "products": [ { "productId": 77130, "vertical": 1, "horizontal": 1, "width": 0.058, "height": 0.1, "depth": 0.058, "depthFacings": 1, "crush": null, "rotation": "FRONT_0", "rotations": [], "type": "SKU", "placementId": "3b4cb2a6-6449-41d8-9b3e-20544cae7630" } ], "coordinates": null, "placementId": "e880cc65-7a04-4867-8c72-9d7d5a8ca6db" } ], "placementId": "1369a56d-f189-4796-9795-51ae663ed5bf" } ], "coordinates": null, "placementId": "b2c956bb-c856-47e4-9bd4-ed41f4f1b2bd" } ], "bayType": "WALLBAY", "placementId": "9e43c0b4-1838-4be0-a30f-1cda435b1f06" }, { "width": 1, "depth": 0.37, "fixtureId": 3, "fixture": { "height": 1.29, "wallThickness": null, "topBarHeight": null, "topBarDepth": null, "startNotchOffset": null, "sidewallsWidth": null, "kickplateHeight": 0.14, "notchSpacing": 0.0491, "maxNotch": 22, "readOnlyBaseFurniture": { "id": 1, "name": "FixtureTest", "shelfThickness": 0.015, "defaultShelfDepth": 0.37 } }, "shelves": [ { "thickness": 0.015, "xOffset": null, "alignment": "EVEN", "width": 1, "height": 0, "depth": 0.37, "products": [ { "productId": 77130, "vertical": 1, "horizontal": 1, "width": 0.199, "height": 0.26, "depth": 0.199, "depthFacings": 1, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "9b03aedd-9907-46dd-a2d0-612efa5ce420" }, { "productId": 111111111, "vertical": 2, "horizontal": 2, "width": 0.195, "height": 0.105, "depth": 0.195, "depthFacings": 1, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "92d4cc7e-7585-44de-a3a3-a54c2c5dca29" } ], "placementId": "93b3123f-6d21-4675-9c82-7b80db585355" }, { "thickness": 0.015, "xOffset": null, "alignment": "LTR", "width": 1, "height": 0.65, "depth": 0.34, "products": [ { "productId": 4000, "vertical": 1, "horizontal": 1, "width": 0.158, "height": 0.267, "depth": 0.158, "depthFacings": 2, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "cd3fc490-ec29-4c0a-9dfc-6f94cf7839a1" }, { "productId": 77130, "vertical": 1, "horizontal": 1, "width": 0.199, "height": 0.26, "depth": 0.199, "depthFacings": 1, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "8b2a355c-f9fa-4f24-8d7c-688d93d41364" }, { "productId": 36085, "vertical": 1, "horizontal": 1, "width": 0.195, "height": 0.265, "depth": 0.195, "depthFacings": 1, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "43a71410-9d29-4f40-b13b-7a0aa1c211fc" } ], "placementId": "2dd2790d-818e-496e-81d6-72867e1f2bc4" }, { "thickness": 0.015, "xOffset": null, "alignment": "RTL", "width": 1, "height": 1, "depth": 0.34, "products": [ { "productId": 4000, "vertical": 1, "horizontal": 1, "width": 0.158, "height": 0.267, "depth": 0.158, "depthFacings": 2, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "f226a73b-0d7f-4e1c-ad59-6e58e0472d67" }, { "productId": 77130, "vertical": 1, "horizontal": 1, "width": 0.199, "height": 0.26, "depth": 0.199, "depthFacings": 1, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "175a9706-cc03-49d1-a7e2-66c1e527ff07" }, { "productId": 4000, "vertical": 1, "horizontal": 1, "width": 0.158, "height": 0.267, "depth": 0.158, "depthFacings": 2, "rotation": "FRONT_0", "crush": { "x": null, "y": null, "z": null }, "type": "SKU", "placementId": "9498dd23-efa2-476b-9e31-316d93ab2f8a" } ], "placementId": "ad673888-dffd-403c-af35-f85d61b3046f" } ], "bayType": "GONDOLA", "placementId": "a4622c4c-85ae-4b44-842e-ed2a3b8942ac" } ] } var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Native structuredClone
myCopy = structuredClone(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
29706.3 Ops/sec
Native structuredClone
36047.2 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark JSON provided compares two methods of deep cloning an object in JavaScript: using **Lodash's `cloneDeep`** method and the built-in **`structuredClone`** method available in modern browsers. Here’s a detailed breakdown of what is being tested and the implications of each approach. ### Options Compared 1. **Lodash `cloneDeep`**: - **Test Name**: Lodash cloneDeep - **Benchmark Definition**: `myCopy = _.cloneDeep(MyObject);` - **Library**: Lodash is a popular utility library in JavaScript that provides functions for common programming tasks, including deep cloning, manipulation of arrays and objects, and more. `cloneDeep` creates a deep copy of a value, meaning it recursively copies all properties, regardless of how deeply nested they are. 2. **Native `structuredClone`**: - **Test Name**: Native structuredClone - **Benchmark Definition**: `myCopy = structuredClone(MyObject);` - **Feature**: `structuredClone` is a native browser function designed to create a deep copy of a JavaScript object. It supports a wider range of data types than traditional cloning methods such as `JSON.parse(JSON.stringify(...))`, including Date objects, Maps, Sets, and others. ### Performance Results From the benchmark results: - **Native structuredClone** executed approximately **36,047.19** executions per second. - **Lodash cloneDeep** executed approximately **29,706.29** executions per second. ### Pros and Cons #### Lodash `cloneDeep` - **Pros**: - Versatile and widely used, making it a well-tested solution. - Can handle a variety of complex data structures effectively. - **Cons**: - Performance might not be as fast as structuredClone in modern browsers, as indicated by the benchmark. - Introduces an additional dependency to your project (the Lodash library), which can increase bundle size and potentially impact loading times. #### Native `structuredClone` - **Pros**: - Built into the browser, no external libraries are required. - Generally faster than Lodash's `cloneDeep`, especially for simple structures. - Supports deep cloning of built-in objects that are otherwise tricky to clone (e.g., Dates, Maps, Sets). - **Cons**: - Not supported in older browsers (though widely supported in modern environments). - Limited in terms of customization; it will only clone data types that are structurally cloneable; certain instances (like functions or DOM nodes) might not be handled appropriately. ### Other Considerations - **Alternatives**: - **JSON.stringify/JSON.parse**: This method can be used for deep cloning objects but fails for non-serializable types such as Functions, Dates, or undefined. - **Manual Cloning**: You can create your own deep clone function tailored to your specific data structure. This approach can be complex and error-prone but may yield optimal performance for particular use cases. - **Use Case Considerations**: Choosing between these options depends on the specific requirements of your application. If you need to clone objects containing complex types, `structuredClone` is often preferable. However, if your project heavily relies on Lodash, or if you need specific features that Lodash's `cloneDeep` offers, then Lodash may be the better choice despite its slightly slower performance. Overall, the benchmark results indicate that if raw performance is your main goal and you're working in a modern environment, **`structuredClone` is the better option**. However, if you require advanced cloning capabilities or are already using Lodash in your project, **`cloneDeep` remains a strong contender**.
Related benchmarks:
test clone
lodash vs native Clone
Lodash cloneDeep vs structuredClone with large object
Lodash cloneDeep vs structuredClone (small & large objects) #2
Lodash cloneDeep vs structuredClone 300KB
Lodash cloneDeep vs structuredClone vs recursiveDeepCopy vs JSON clone (larger object)
object clone 2
Lodash cloneDeep vs structuredClone w/ larger payload
lodash cloneDeep vs structuredClone on larger object and with arrays
Comments
Confirm delete:
Do you really want to delete benchmark?