Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
large json test: simpleStringify vs JSON.stringify
(version: 0)
Comparing performance of:
simpleStringify vs JSON.stringify
Created:
6 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function simpleStringify(o) { let cache = []; let data = JSON.stringify(o, function(key, value) { if (typeof value === "object" && value !== null) { if (cache.indexOf(value) !== -1) { // Circular reference found, discard key return; } // Store value in our collection cache.push(value); } return value; }); cache = null; return data; } var testData = {"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"}}};
Tests:
simpleStringify
simpleStringify(testData);
JSON.stringify
JSON.stringify(testData)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
simpleStringify
JSON.stringify
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):
Measuring performance differences between two approaches for serializing JavaScript objects is an interesting task. **Benchmark Definition** The benchmark definition consists of two scripts: `simpleStringify` and `JSON.stringify`. The `simpleStringify` function manually implements the serialization process, while `JSON.stringify` uses the built-in JSON serializer. **Options Compared** * **Simple Stringification (manual implementation)**: * Pros: * Can potentially provide more control over the serialization process. * May be able to optimize for specific use cases. * Cons: * Requires manual implementation, which can increase complexity and debugging time. * May not be optimized for general-purpose serialization. * **JSON Stringification (built-in)**: * Pros: * Widely supported and well-tested. * Optimized for performance and compatibility. * Cons: * Less control over the serialization process. * May not be able to optimize for specific use cases. **Library Used** The `simpleStringify` function uses a simple caching mechanism to avoid serializing circular references. The cache is implemented using an array (`cache`), which stores values that have already been serialized. **Individual Test Cases** There are two test cases: * **simpleStringify**: This test case runs the `simpleStringify(testData)` function, where `testData` is a complex JavaScript object containing various serializable and non-serializable properties. * **JSON.stringify**: This test case runs the `JSON.stringify(testData)` function, which serializes the same `testData` object using the built-in JSON serializer. **Latest Benchmark Result** The latest benchmark result shows that: * The `simpleStringify` approach has a higher execution frequency per second (103578.625) compared to the `JSON.stringify` approach (54183.125). However, this may be due to the caching mechanism in `simpleStringify`, which avoids unnecessary serializations. * Both approaches have similar performance characteristics on this specific test case. In conclusion, while the `simpleStringify` function provides more control over the serialization process, it also introduces additional complexity and debugging time. The built-in `JSON.stringify` function is widely supported, optimized for performance, and suitable for most use cases.
Related benchmarks:
simpleStringify vs JSON.stringify
simpleStringify vs JSON.stringify2
simpleStringify vs JSON.stringify3
simpleStringify vs JSON.stringify 2
Comments
Confirm delete:
Do you really want to delete benchmark?