Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
cloneDeep vs structuredClone vs JSON clone
(version: 0)
Comparing performance of:
cloneDeep vs structuredClone vs JSON clone
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.5/lodash.min.js'></script>
Script Preparation code:
var obj = [{"value":"64d4ac801e7ca8220d469901","title":"Bonner Carter"},{"value":"64d4ac8023a44301222299b6","title":"Candice Hoffman"},{"value":"64d4ac805d14b4ddca7caa0b","title":"Tamika Sanders"},{"value":"64d4ac807ccfee17f96a49c3","title":"Amie Bray"},{"value":"64d4ac80300d509a539e9352","title":"Giles Weeks"},{"value":"64d4ac805d12705449dc3703","title":"Leonard Salinas"},{"value":"64d4ac80807a84e72f802e54","title":"Hansen Brooks"},{"value":"64d4ac8063359f660571b4f1","title":"Ursula Cherry"},{"value":"64d4ac805d660307afabec7b","title":"Stephens Munoz"},{"value":"64d4ac80f58786476d3987ea","title":"Goldie Mendoza"},{"value":"64d4ac80d11b8f4f25ee15f7","title":"Fitzpatrick Nolan"},{"value":"64d4ac80236858817a1fcea1","title":"Jenkins Ferguson"},{"value":"64d4ac80424663ca6d377ce2","title":"Espinoza Barry"},{"value":"64d4ac80593a15689685bc5d","title":"Decker Erickson"},{"value":"64d4ac8011354f87753aba5d","title":"Kline Bernard"},{"value":"64d4ac80e7fe829b47a12aed","title":"Doyle Kramer"},{"value":"64d4ac80eca2833396efe0f9","title":"Leblanc Ware"},{"value":"64d4ac802cbfc90e08de6e94","title":"Sweet Gibson"},{"value":"64d4ac80593e6b41b1912055","title":"Aguilar Ramsey"},{"value":"64d4ac807ff4fa3b8352a831","title":"Mae Davis"},{"value":"64d4ac8049a89897367dfde0","title":"Lynda Kidd"},{"value":"64d4ac803f7f1b18898b20c0","title":"Rosalie Fisher"},{"value":"64d4ac800196555f2231d9fb","title":"Daugherty Hancock"},{"value":"64d4ac80866eaf9f4cefdcc4","title":"Ashley Osborn"},{"value":"64d4ac80c97490d55d7fbba6","title":"Rosanne Bruce"},{"value":"64d4ac80b20c941acf802827","title":"Lois Strong"},{"value":"64d4ac80d3652e8db1904559","title":"Cummings Austin"},{"value":"64d4ac8007fcbff6191d9d01","title":"Faith Kelly"},{"value":"64d4ac8031aa3f833a750788","title":"Ines Leonard"},{"value":"64d4ac80d97e342999c6662b","title":"Fulton Richard"},{"value":"64d4ac802bae78c7c91ee4cf","title":"Baird Shepard"},{"value":"64d4ac80b30ad4c024e7dd9c","title":"Jordan Santiago"},{"value":"64d4ac80faae3a4da999330f","title":"Staci Henry"},{"value":"64d4ac803b7d9833602c2070","title":"Billie Wilson"},{"value":"64d4ac80085e765a600f6493","title":"Mccarty Hester"},{"value":"64d4ac804eb6486ebac6c1aa","title":"Melva Ramirez"},{"value":"64d4ac80dc9ea632842d1fe5","title":"Talley Richards"},{"value":"64d4ac80ebdd65cb42841618","title":"Catherine Cox"},{"value":"64d4ac80206934d10e258d4e","title":"Kellie Knight"},{"value":"64d4ac8038820299f08623f5","title":"Rice Mccarty"},{"value":"64d4ac80e07894987d93e767","title":"Gallagher Coffey"},{"value":"64d4ac80f2dc6b7e205ea236","title":"Rich Dale"},{"value":"64d4ac80393839c556a8f296","title":"Baxter Jordan"},{"value":"64d4ac80b6159f7446f92d44","title":"Chris Marsh"},{"value":"64d4ac80529489bce3e166d1","title":"Nicholson Schmidt"},{"value":"64d4ac8055fe9d8ccdd2d1cf","title":"Juliette Keith"},{"value":"64d4ac80fabd757086545fde","title":"Krista Miller"},{"value":"64d4ac80e7991bea8aed4146","title":"Ofelia House"},{"value":"64d4ac8004f38858ea0da2f8","title":"Chen Travis"},{"value":"64d4ac80bd732c83368742c8","title":"Gates Baker"},{"value":"64d4ac8014c5f503f8700667","title":"Miranda Houston"},{"value":"64d4ac80f444744780218d29","title":"Darcy Kim"},{"value":"64d4ac8077b63021666b1e76","title":"Terry Riddle"},{"value":"64d4ac80cfb5ab6867f40e93","title":"Diann Roy"},{"value":"64d4ac80997e1e5682580c8f","title":"Welch Copeland"},{"value":"64d4ac8039c7407270052c23","title":"Pitts Stokes"},{"value":"64d4ac80c93a19ccdb4af6c0","title":"Benson Bauer"},{"value":"64d4ac80396d02463d9d765c","title":"Blair Clarke"},{"value":"64d4ac8055aaa95dcc0c7cb8","title":"Penny Ortega"},{"value":"64d4ac804b99685c6817d880","title":"Shannon Sims"},{"value":"64d4ac80666cdc9eac1314ca","title":"Branch Landry"},{"value":"64d4ac80e81678a0c6feb8e5","title":"Lewis Head"},{"value":"64d4ac80728253a9b153112e","title":"Buckner Stein"},{"value":"64d4ac80d926be3e41d2fca5","title":"Jeri Frederick"},{"value":"64d4ac80d6db663f79d8815c","title":"Mai Ellis"},{"value":"64d4ac80305f706150ae23b6","title":"Bennett Rodriquez"},{"value":"64d4ac80e7cffb1529f8abf6","title":"Millie Avery"},{"value":"64d4ac801895f2c2507955cf","title":"Mcfadden Hull"},{"value":"64d4ac807cf10c7e67a0240e","title":"Vance Haynes"},{"value":"64d4ac809575fd8bf0652fd1","title":"Hunt Carey"},{"value":"64d4ac80ff17023ab9d2405f","title":"Slater Forbes"},{"value":"64d4ac8055d6039b3778e935","title":"Garrett Simmons"},{"value":"64d4ac808ea6d16fc94f8890","title":"Payne Moody"},{"value":"64d4ac80b4b92d542df83447","title":"Mclean Drake"},{"value":"64d4ac803b947315366cacd9","title":"Gonzales Waller"},{"value":"64d4ac80754755b614fbb6ba","title":"Hebert Long"},{"value":"64d4ac80ed985c313140ea2e","title":"Felicia Nieves"},{"value":"64d4ac800f8d5e04d3fdca33","title":"Schultz Buckner"},{"value":"64d4ac8062d18d6d67506fe8","title":"Shelton Fox"},{"value":"64d4ac806f9c7ff1ed91a0eb","title":"Clarissa Schwartz"},{"value":"64d4ac80b6bc4fe597d0b2d7","title":"Solomon Phelps"},{"value":"64d4ac80b0fe321c1778be5a","title":"Edwina Kirk"},{"value":"64d4ac80e96ae90ea398ecf3","title":"Elnora Flowers"},{"value":"64d4ac80fe0fded27b1fc2e0","title":"Lindsey Powers"},{"value":"64d4ac80268e69417823c909","title":"Antoinette Strickland"},{"value":"64d4ac8007473c887b242ca3","title":"Noemi Randolph"},{"value":"64d4ac8024051f4b76312c90","title":"Ophelia Harrell"},{"value":"64d4ac801bb2266e32e43bed","title":"Harris Bullock"},{"value":"64d4ac80193320bd4e847fcb","title":"Sonia Solis"},{"value":"64d4ac80c2f86c283b92e88c","title":"Moon Pittman"},{"value":"64d4ac807456389975b4b938","title":"Greta Holder"},{"value":"64d4ac8022a6e82947f712c3","title":"Stone Chavez"},{"value":"64d4ac808d57a8261e780870","title":"Francis Taylor"},{"value":"64d4ac8022bbd3ce041fe603","title":"Lori Rosario"},{"value":"64d4ac80836111e246818ed4","title":"Jana Blackwell"},{"value":"64d4ac80eb6323bdb53526c2","title":"Shaw Hubbard"},{"value":"64d4ac80ebeee6ff28928183","title":"Selena Buckley"},{"value":"64d4ac80031614e0a3fefa47","title":"Mitzi Mathews"},{"value":"64d4ac80f576ee8295c4b477","title":"Gross Bell"},{"value":"64d4ac802f9b38a57dd84dde","title":"Florine Mullins"}]; var result = null;
Tests:
cloneDeep
result = _.cloneDeep(obj);
structuredClone
result = structuredClone(obj);
JSON clone
result = JSON.parse(JSON.stringify(obj));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
cloneDeep
structuredClone
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):
The provided information is a combination of benchmarking test cases and results, including: 1. A large JSON object `obj` with multiple properties and values. 2. Three individual test cases for benchmarking: * Cloning the object using Lodash's `cloneDeep` function. * Cloning the object using the Web API's `structuredClone` function. * Cloning the object using the `JSON.parse(JSON.stringify(obj))` method. 3. The raw UA string and browser information for a Chrome 115 browser on a Windows desktop platform, indicating that the benchmarking tests were run in this environment. To answer the question accurately, I would need more context or specific details about what is being asked, such as: * What are the expected outputs or results of the benchmarking tests? * Are there any specific errors or edge cases to consider? * Is there a particular aspect of the JSON object or benchmarking process that requires attention? Given the information provided, I'll assume a general approach: **Solution** Based on the provided test cases and their respective benchmarking functions, here's a possible approach to resolve the issue: 1. **Clone the Object using Lodash**: For the `cloneDeep` function from Lodash, you can use it as is: ```javascript const result = _.cloneDeep(obj); ``` 2. **Clone the Object using Structured Clone**: To clone the object using structured clone, you would typically use a library like `structured-cloned`. However, since this library is not mentioned in the provided code snippet, I'll skip implementation details for now. 3. **Clone the Object using JSON.parse(JSON.stringify())**: For the `JSON parse` method, ensure that your object does not contain any cyclic references or properties with unserializable values (like functions). If necessary, use a custom serialization function to avoid issues: ```javascript const result = JSON.parse(JSON.stringify(obj)); ``` **Example Implementation** Here's an example implementation using Lodash and JavaScript: ```javascript // Import Lodash import _ from 'lodash'; function cloneObjectUsingLodash() { // Clone the object using Lodash const result = _.cloneDeep(obj); return result; } // Example usage: const obj = { a: 1, b: [2, 3], c: { d: 4 }, }; console.log(cloneObjectUsingLodash()); ``` **Note**: This implementation assumes that the `obj` variable is defined and available within the function scope. You should replace this with your actual object definition. To address the question directly: * **What are the expected outputs or results of the benchmarking tests?** The expected output depends on the specific requirements of your application. For example, if you want to preserve the original structure and values of the `obj` during cloning, use Lodash's `cloneDeep`. If preserving the structure is not a priority but speed is, consider using structured clone. * **Are there any specific errors or edge cases to consider?** Yes: * Be cautious when dealing with cyclic references in objects, as they can lead to infinite recursion and errors. * JSON parse can fail if the object contains unserializable values (like functions) or cyclic references. * Consider using custom serialization techniques for objects that cannot be serialized directly. For more information about structured clone and its usage, refer to [the official documentation](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone).
Related benchmarks:
Lodash cloneDeep vs JSON Clone large Json
Lodash cloneDeep vs JSON Clone Large object
Lodash(v4.17.21) cloneDeep vs JSON Clone Larger object
Lodash cloneDeep vs JSON Clone vs Ramda Clone for big Array
Comments
Confirm delete:
Do you really want to delete benchmark?