Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash deep clone vs JSON.stringfy davide
(version: 0)
Comparing performance of:
Lodash deep clone vs JSON.stringfy
Created:
5 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:
window.obj = { foo: [ { "_id": "5f0e234eae0b7c7049455e21", "index": 0, "guid": "c0b87d1e-dcd7-48e1-b317-77f691eb09dc", "isActive": true, "balance": "$3,947.73", "picture": "http://placehold.it/32x32", "age": 33, "eyeColor": "green", "name": { "first": "Lewis", "last": "Langley" }, "company": "IMPERIUM", "email": "lewis.langley@imperium.co.uk", "phone": "+1 (892) 445-2138", "address": "690 Bevy Court, Riviera, Colorado, 6304", "about": "Consectetur ea nisi elit velit nostrud tempor. Veniam sint irure in ut voluptate dolore. Ea nostrud nisi anim laborum id aliqua excepteur culpa. Et laborum nostrud veniam id commodo et officia ex do ex.", "registered": "Wednesday, September 13, 2017 5:01 AM", "latitude": "11.16502", "longitude": "-61.446543", "tags": [ "in", "do", "eiusmod", "deserunt", "esse" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Addie Blanchard" }, { "id": 1, "name": "Curry Slater" }, { "id": 2, "name": "Terry Gallagher" } ], "greeting": "Hello, Lewis! You have 7 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5f0e234ee581ed80b7636627", "index": 1, "guid": "5ffe2c82-3646-49c4-a327-70ddea6b75f2", "isActive": false, "balance": "$3,510.38", "picture": "http://placehold.it/32x32", "age": 22, "eyeColor": "green", "name": { "first": "Kristen", "last": "Scott" }, "company": "EXOSTREAM", "email": "kristen.scott@exostream.biz", "phone": "+1 (939) 511-3250", "address": "925 Kiely Place, Rosedale, Missouri, 1557", "about": "Nulla excepteur minim in reprehenderit ea elit veniam excepteur. Adipisicing reprehenderit cillum amet magna sit exercitation voluptate irure. Est id ipsum aliqua adipisicing ex minim elit sit esse esse sit. In occaecat id non nisi aliquip cupidatat nulla proident in non fugiat eu sit eu. Aliquip deserunt dolore ea veniam excepteur consectetur eu quis aliqua proident proident irure adipisicing.", "registered": "Monday, July 6, 2020 3:00 PM", "latitude": "83.228281", "longitude": "56.108607", "tags": [ "aliqua", "reprehenderit", "laborum", "non", "irure" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Armstrong Carr" }, { "id": 1, "name": "Sara Blevins" }, { "id": 2, "name": "Jean Walter" } ], "greeting": "Hello, Kristen! You have 9 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5f0e234edcbf1f13dcc3c3df", "index": 2, "guid": "21c55551-7ec2-4e5c-8738-a641e3b23237", "isActive": false, "balance": "$1,455.81", "picture": "http://placehold.it/32x32", "age": 29, "eyeColor": "green", "name": { "first": "Deann", "last": "Solis" }, "company": "COMVOY", "email": "deann.solis@comvoy.us", "phone": "+1 (852) 481-2132", "address": "455 Overbaugh Place, Munjor, Tennessee, 2750", "about": "Laborum irure in ullamco excepteur esse ex qui. Laborum aliqua adipisicing id ex cillum mollit. Reprehenderit magna dolor consectetur reprehenderit.", "registered": "Friday, February 22, 2019 8:44 PM", "latitude": "65.22083", "longitude": "-147.202219", "tags": [ "eu", "dolore", "quis", "esse", "consectetur" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Trisha Maynard" }, { "id": 1, "name": "Elliott Carver" }, { "id": 2, "name": "Mcfadden Olsen" } ], "greeting": "Hello, Deann! You have 6 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5f0e234ea4862691fe9ae4b9", "index": 3, "guid": "10ba5ae7-f4fb-476b-862a-fb5c3e99f72b", "isActive": true, "balance": "$1,351.24", "picture": "http://placehold.it/32x32", "age": 28, "eyeColor": "green", "name": { "first": "Deloris", "last": "Cash" }, "company": "EARTHMARK", "email": "deloris.cash@earthmark.net", "phone": "+1 (823) 406-2118", "address": "315 Shale Street, Glasgow, Hawaii, 7990", "about": "Ut non minim elit fugiat culpa excepteur minim cupidatat. Sunt eu consectetur enim ut ut. Tempor ea id irure tempor dolor velit in consectetur in ad aliqua.", "registered": "Sunday, April 28, 2019 10:24 AM", "latitude": "-20.47693", "longitude": "91.374667", "tags": [ "tempor", "laborum", "consectetur", "amet", "amet" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Rutledge Graves" }, { "id": 1, "name": "Eliza Mullen" }, { "id": 2, "name": "Cannon Castillo" } ], "greeting": "Hello, Deloris! You have 9 unread messages.", "favoriteFruit": "apple" }, { "_id": "5f0e234eee259b6da65a3767", "index": 4, "guid": "b2319832-cf5d-427d-bc3a-5b6b0f157a66", "isActive": false, "balance": "$1,541.50", "picture": "http://placehold.it/32x32", "age": 26, "eyeColor": "brown", "name": { "first": "Dianna", "last": "Marks" }, "company": "UTARIAN", "email": "dianna.marks@utarian.biz", "phone": "+1 (828) 451-2194", "address": "820 Louise Terrace, Nadine, Oregon, 8854", "about": "Excepteur cupidatat amet duis minim eu qui eiusmod consequat nisi officia. Irure dolore enim sit ullamco elit amet culpa. Pariatur reprehenderit cupidatat nulla exercitation nisi amet dolor excepteur nulla esse eiusmod et. Proident enim qui ea culpa sit do nostrud sit adipisicing voluptate.", "registered": "Wednesday, October 24, 2018 4:33 PM", "latitude": "-7.685072", "longitude": "116.690599", "tags": [ "aliquip", "enim", "mollit", "qui", "cillum" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Juliette Huff" }, { "id": 1, "name": "Diaz Lara" }, { "id": 2, "name": "Helen Mccoy" } ], "greeting": "Hello, Dianna! You have 5 unread messages.", "favoriteFruit": "banana" }, { "_id": "5f0e234ed143a73c9d20b8ff", "index": 5, "guid": "718b3ef7-3bb3-4c30-997f-b3f7bb133b78", "isActive": true, "balance": "$1,879.46", "picture": "http://placehold.it/32x32", "age": 23, "eyeColor": "brown", "name": { "first": "Robyn", "last": "Ryan" }, "company": "PRINTSPAN", "email": "robyn.ryan@printspan.info", "phone": "+1 (996) 477-2985", "address": "713 Madeline Court, Malott, California, 2425", "about": "Aute proident enim irure aliqua officia consequat voluptate duis cupidatat tempor Lorem. Officia veniam do occaecat ut ipsum excepteur quis. Adipisicing officia nostrud deserunt excepteur est exercitation in incididunt id eiusmod pariatur. Labore occaecat ea veniam et in ad commodo anim minim nulla. Labore id dolore dolore ut tempor ex et et duis. Cupidatat sint in in sunt ex incididunt adipisicing consequat sunt eiusmod. Esse exercitation dolore duis laborum amet labore Lorem sit laboris dolor.", "registered": "Wednesday, March 19, 2014 7:22 AM", "latitude": "31.358432", "longitude": "0.064057", "tags": [ "pariatur", "mollit", "ea", "id", "eu" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Yates Christensen" }, { "id": 1, "name": "Leigh Kennedy" }, { "id": 2, "name": "Ortiz Mcfadden" } ], "greeting": "Hello, Robyn! You have 8 unread messages.", "favoriteFruit": "apple" }, { "_id": "5f0e234ec3f3b8d9e6d9785d", "index": 6, "guid": "e88b593c-7ce7-4c38-8531-f4948117cb51", "isActive": true, "balance": "$2,427.27", "picture": "http://placehold.it/32x32", "age": 36, "eyeColor": "green", "name": { "first": "Bird", "last": "Carpenter" }, "company": "RECRISYS", "email": "bird.carpenter@recrisys.io", "phone": "+1 (841) 422-3795", "address": "642 Eaton Court, Brantleyville, Idaho, 3510", "about": "Nisi excepteur anim cupidatat ea ut sit commodo enim. Voluptate non dolor sit consequat cillum laboris mollit tempor eu mollit deserunt anim laborum pariatur. Velit consequat aliqua incididunt dolor proident exercitation ad. Consectetur sint Lorem id id nostrud qui et deserunt velit duis.", "registered": "Saturday, December 12, 2015 9:53 PM", "latitude": "76.835174", "longitude": "-97.928709", "tags": [ "velit", "ad", "cillum", "ea", "laboris" ], "range": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "friends": [ { "id": 0, "name": "Myrna Logan" }, { "id": 1, "name": "Franklin Holcomb" }, { "id": 2, "name": "Mai Mathis" } ], "greeting": "Hello, Bird! You have 5 unread messages.", "favoriteFruit": "banana" } ] }
Tests:
Lodash deep clone
const objClone = _.cloneDeep(window.obj);
JSON.stringfy
const objClone = JSON.parse(JSON.stringify(window.obj));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash deep clone
JSON.stringfy
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):
I'll provide an answer based on the provided JSON data. **JSON Data Analysis** The provided JSON data is an object that contains information about two individuals: 1. The first individual has the following attributes: * `_id`: `5f0e234ec3f3b8d9e6d9785d` * `index`: 6 * `guid`: `e88b593c-7ce7-4c38-8531-f4948117cb51` * `isActive`: true * `balance`: `$2,427.27` * `picture`: `http://placehold.it/32x32` * `age`: 36 * `eyeColor`: `green` * `name`: `Bird Carpenter` * `company`: `RECRISYS` * `email`: `bird.carpenter@recrisys.io` * `phone`: `+1 (841) 422-3795` * `address`: `642 Eaton Court, Brantleyville, Idaho, 3510` * `about`: A long text describing the person * `registered`: `Saturday, December 12, 2015 9:53 PM` * `latitude` and `longitude`: `76.835174` and `-97.928709`, respectively * `tags`: An array of strings (`velit`, `ad`, `cillum`, `ea`, `laboris`) * `range`: An array of numbers (0-9) * `friends`: An array of objects with `id` and `name` attributes 2. The second individual has similar attributes, but with a different `favoriteFruit` value (`banana`). **Lodash Deep Clone vs JSON.stringify** The two test cases are: 1. Lodash deep clone using `_cloneDeep` 2. JSON.stringify Both test cases aim to create a copy of the original object. However, they use different methods to achieve this. In general, `JSON.stringify` is a safer and more reliable method for creating a copy of an object, as it ensures that all nested objects are properly serialized. On the other hand, `_cloneDeep` from Lodash can lead to issues with cyclic references or deeply nested objects. **Benchmark Results** The latest benchmark results show: 1. JSON.stringify: 19619 executions per second 2. Lodash deep clone (`_cloneDeep`): 17322 executions per second The results suggest that `JSON.stringify` is slightly faster than Lodash deep clone, but this may depend on the specific use case and input data. **Conclusion** While both methods can be used to create a copy of an object, `JSON.stringify` is generally a safer choice due to its ability to properly serialize nested objects. If you need to perform frequent cloning operations, using `JSON.stringify` might be a better option, despite the slightly lower performance compared to Lodash deep clone.
Related benchmarks:
Lodash cloneDeep vs JSON Clone (Large Object 2)
Lodash deep clone vs JSON.stringfy
Lodash deeper clone vs Spread Clone
cloneDeep vs JSON stringify + parse (long arr)
Object cloning with Lodash clone vs cloneDeep vs merge vs structuredClone vs JSON.parse(JSON.stringify(o))
Comments
Confirm delete:
Do you really want to delete benchmark?