Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
deep clean - recure function vs json.stringify
(version: 1)
Comparing performance of:
clean function vs dfdffd
Created:
3 years ago
by:
Registered User
Jump to the latest result
Tests:
clean function
var object = { "name": "ddfdf", "description": null, "resourceGroupName": "yuvalResourceGroup", "region": "eastus", "persistence": { "shouldPersistOsDisk": true, "osDiskPersistenceMode": "reattach", "shouldPersistDataDisks": true, "dataDisksPersistenceMode": "reattach", "shouldPersistNetwork": null }, "compute": { "vmSizes": { "spotSizes": [ "basic_a0" ], "odSizes": [ "basic_a0" ], "preferredSpotSizes": [ "basic_a0" ] }, "zones": [ "1" ], "os": "Linux", "launchSpecification": { "customData": null, "shutdownScript": null, "network": {}, "login": { "userName": "sdds", "password": "dfdsffsd#@23FD", "sshPublicKey": null }, "image": { "custom": null, "marketplace": { "publisher": "Canonical", "offer": "UbuntuServer", "sku": "14.04.0-LTS", "version": "latest" }, "gallery": null } } }, "strategy": { "drainingTimeout": 120, "fallbackToOd": true, "optimizationWindows": null, "preferredLifecycle": null, "revertToSpot": { "performAt": "always" } } }; function clean(object) { Object .entries(object) .forEach(([k, v]) => { if (v && typeof v === 'object') { clean(v); } if (v && typeof v === 'object' && !Object.keys(v).length || v === null || v === undefined) { if (Array.isArray(object)) { object.splice(k, 1); } else { delete object[k]; } } }); return object; } clean(object);
dfdffd
var object = { "name": "ddfdf", "description": null, "resourceGroupName": "yuvalResourceGroup", "region": "eastus", "persistence": { "shouldPersistOsDisk": true, "osDiskPersistenceMode": "reattach", "shouldPersistDataDisks": true, "dataDisksPersistenceMode": "reattach", "shouldPersistNetwork": null }, "compute": { "vmSizes": { "spotSizes": [ "basic_a0" ], "odSizes": [ "basic_a0" ], "preferredSpotSizes": [ "basic_a0" ] }, "zones": [ "1" ], "os": "Linux", "launchSpecification": { "customData": null, "shutdownScript": null, "network": {}, "login": { "userName": "sdds", "password": "dfdsffsd#@23FD", "sshPublicKey": null }, "image": { "custom": null, "marketplace": { "publisher": "Canonical", "offer": "UbuntuServer", "sku": "14.04.0-LTS", "version": "latest" }, "gallery": null } } }, "strategy": { "drainingTimeout": 120, "fallbackToOd": true, "optimizationWindows": null, "preferredLifecycle": null, "revertToSpot": { "performAt": "always" } } }; function clean(object) { Object .entries(object) .forEach(([k, v]) => { if (v && typeof v === 'object') { clean(v); } if (v && typeof v === 'object' && !Object.keys(v).length || v === null || v === undefined) { if (Array.isArray(object)) { object.splice(k, 1); } else { delete object[k]; } } }); return object; } clean(object);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
clean function
dfdffd
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):
Let's break down what's being tested in the provided JSON. The benchmark is testing two approaches to deep cleaning an object: 1. **Recursive function**: The `clean` function uses recursion to delete nested objects and arrays from the input object. It checks if each value (v) is an object, and if so, calls itself with that object as an argument. If the object has no keys or its value is null/undefined, it attempts to remove it from the original object. 2. **JSON.stringify**: The `clean` function also uses JSON.stringify to create a string representation of the input object, which can then be compared for equality. **Options being compared:** * Recursive function (with custom implementation) * JSON.stringify (built-in JavaScript method) **Pros and Cons of each approach:** 1. **Recursive function**: + Pros: - Can handle complex nested objects - Can be optimized for specific use cases + Cons: - Can lead to stack overflow errors if not implemented carefully - May be slower than other approaches due to recursive calls 2. **JSON.stringify**: + Pros: - Fast and efficient, as it uses a built-in method - Can handle large objects without performance issues + Cons: - May not work correctly for objects with circular references - May produce unexpected results if the object is modified after stringification **Other considerations:** * Both approaches assume that the input object has a specific structure and does not contain any cyclic references. * The `clean` function does not handle cases where the input object is null or undefined. * The benchmark results may vary depending on the JavaScript engine, version, and platform used. In general, the choice between these two approaches depends on the specific requirements of the use case. If performance is critical and the input objects are expected to be simple and well-structured, JSON.stringify might be a better choice. However, if the input objects can be complex or have unexpected structures, the recursive function implementation may be necessary.
Related benchmarks:
Lodash cloneDeep vs JSON Clone deeper1
lodash clonedeep vs json.parse(stringify()) vs recursivecopy vs shallowcopy
lodash clonedeep vs json.parse(stringify()) vs structuredClone
lodash clonedeep vs json.parse(stringify()) vs recursivecopy new big
lodash clonedeep vs json.parse(stringify()) vs recursivecopy heavy
Comments
Confirm delete:
Do you really want to delete benchmark?