Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash3 cloneDeep vs JSON Clone (BIG OBJECT)
(version: 0)
Comparing performance of:
cloneDeep vs JSON.parse
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://lodash.com/vendor/cdn.jsdelivr.net/lodash/3.10.1/lodash.min.js'></script>
Script Preparation code:
var MyObject = { "web-app": { "servlet": [ { "servlet-name": "cofaxCDS", "servlet-class": "org.cofax.cds.CDSServlet", "init-param": { "configGlossary:installationAt": "Philadelphia, PA", "configGlossary:adminEmail": "ksm@pobox.com", "configGlossary:poweredBy": "Cofax", "configGlossary:poweredByIcon": "/images/cofax.gif", "configGlossary:staticPath": "/content/static", "templateProcessorClass": "org.cofax.WysiwygTemplate", "templateLoaderClass": "org.cofax.FilesTemplateLoader", "templatePath": "templates", "templateOverridePath": "", "defaultListTemplate": "listTemplate.htm", "defaultFileTemplate": "articleTemplate.htm", "useJSP": false, "jspListTemplate": "listTemplate.jsp", "jspFileTemplate": "articleTemplate.jsp", "cachePackageTagsTrack": 200, "cachePackageTagsStore": 200, "cachePackageTagsRefresh": 60, "cacheTemplatesTrack": 100, "cacheTemplatesStore": 50, "cacheTemplatesRefresh": 15, "cachePagesTrack": 200, "cachePagesStore": 100, "cachePagesRefresh": 10, "cachePagesDirtyRead": 10, "searchEngineListTemplate": "forSearchEnginesList.htm", "searchEngineFileTemplate": "forSearchEngines.htm", "searchEngineRobotsDb": "WEB-INF/robots.db", "useDataStore": true, "dataStoreClass": "org.cofax.SqlDataStore", "redirectionClass": "org.cofax.SqlRedirection", "dataStoreName": "cofax", "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", "dataStoreUser": "sa", "dataStorePassword": "dataStoreTestQuery", "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", "dataStoreInitConns": 10, "dataStoreMaxConns": 100, "dataStoreConnUsageLimit": 100, "dataStoreLogLevel": "debug", "maxUrlLength": 500 } }, { "servlet-name": "cofaxEmail", "servlet-class": "org.cofax.cds.EmailServlet", "init-param": { "mailHost": "mail1", "mailHostOverride": "mail2" } }, { "servlet-name": "cofaxAdmin", "servlet-class": "org.cofax.cds.AdminServlet" }, { "servlet-name": "fileServlet", "servlet-class": "org.cofax.cds.FileServlet" }, { "servlet-name": "cofaxTools", "servlet-class": "org.cofax.cms.CofaxToolsServlet", "init-param": { "templatePath": "toolstemplates/", "log": 1, "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", "logMaxSize": "", "dataLog": 1, "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", "dataLogMaxSize": "", "removePageCache": "/content/admin/remove?cache=pages&id=", "removeTemplateCache": "/content/admin/remove?cache=templates&id=", "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", "lookInContext": 1, "adminGroupID": 4, "betaServer": true } } ], "servlet-mapping": { "cofaxCDS": "/", "cofaxEmail": "/cofaxutil/aemail/*", "cofaxAdmin": "/admin/*", "fileServlet": "/static/*", "cofaxTools": "/tools/*" }, "taglib": { "taglib-uri": "cofax.tld", "taglib-location": "/WEB-INF/tlds/cofax.tld" } } }; var data=[] for(var i=0; i<100000; i++){ data.push(MyObject); } var myCopy = null;
Tests:
cloneDeep
myCopy = _.cloneDeep(data);
JSON.parse
myCopy = JSON.parse(JSON.stringify(data));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
cloneDeep
JSON.parse
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 break down the provided benchmark definition, test cases, and latest benchmark results to explain what's being tested. **Benchmark Definition** The benchmark is comparing two approaches to cloning a large JavaScript object: 1. `_.cloneDeep(data)` using Lodash's `cloneDeep` function. 2. `JSON.parse(JSON.stringify(data))`. **What are these functions doing?** * `_.cloneDeep(data)` creates a deep copy of the input object `data`, which means it recursively clones all nested objects and arrays, rather than just copying their references. This ensures that any changes made to the cloned object won't affect the original. * `JSON.parse(JSON.stringify(data))` uses JSON serialization to create a new object that's equivalent to the original `data`. However, this approach has limitations: + It only clones the top-level properties and doesn't recursively clone nested objects or arrays. + It can lead to issues with dates, regular expressions, and other complex data types. **Pros and Cons of each approach** * **_.cloneDeep(data)**: + Pros: Recursively clones all nested objects and arrays, ensures that changes don't affect the original. + Cons: Can be slower due to the recursive cloning process, may consume more memory if dealing with large datasets. * **JSON.parse(JSON.stringify(data))**: + Pros: Fast and efficient for simple data structures, easy to implement. + Cons: Limited to top-level properties, can fail with complex data types (dates, regex), and doesn't ensure deep equality. **Test Cases** The benchmark tests two individual test cases: 1. `_.cloneDeep(data)` 2. `JSON.parse(JSON.stringify(data))` Each test case is designed to measure the performance of its respective cloning approach. **Latest Benchmark Results** The results show that Chrome 80, running on a Mac OS X 10.14.6 desktop, executed each test case: * `_.cloneDeep(data)` at an execution rate of approximately 69 executions per second. * `JSON.parse(JSON.stringify(data))` at an execution rate of approximately 0.36 seconds. These results suggest that the Lodash `cloneDeep` function is significantly faster than using JSON serialization for deep cloning, especially when dealing with large datasets. In conclusion, this benchmark highlights the importance of choosing the right cloning approach based on your specific use case. If you need to ensure deep equality and performance, `_.cloneDeep(data)` might be a better choice. However, if you're working with simple data structures and prioritize speed, `JSON.parse(JSON.stringify(data))` could be sufficient.
Related benchmarks:
Lodash cloneDeep vs JSON Clone (BIG OBJECT)
Lodash cloneDeep vs JSON Clone big object 12345
Lodash (4.17.11) cloneDeep vs JSON Clone vs structuredClone
lodash cloneDeep vs. JSON.parse(JSON.stringify()) vs. structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?