Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep Clone #2
(version: 0)
Comparing performance of:
Req vs json
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function recursiveDeepCopy(obj) { return Object.keys(obj).reduce((v, d) => Object.assign(v, { [d]: (obj[d].constructor === Object) ? recursiveDeepCopy(obj[d]) : obj[d] }), {}); } function jsonDeepCopy(o) { return JSON.parse(JSON.stringify(o)); } var dimensions = [{ "dimensions": [{ "runtime": { "common": { "client": null, "server": null } } }, { "device": { "android": null, "blackberry": null, "iemobile": null, "iphone": null, "ipad": null, "kindle": null, "opera-mini": null, "palm": null } }, { "environment": { "development": { "dev": null, "test": null }, "production": { "stage": null, "prod": null } } }, { "lang": { "ar": { "ar-JO": null, "ar-MA": null, "ar-SA": null, "ar-EG": null }, "bn": { "bn-IN": null }, "ca": { "ca-ES": null }, "cs": { "cs-CZ": null }, "da": { "da-DK": null }, "de": { "de-AT": null, "de-DE": null }, "el": { "el-GR": null }, "en": { "en-AU": null, "en-BG": null, "en-CA": null, "en-GB": null, "en-GY": null, "en-HK": null, "en-IE": null, "en-IN": null, "en-MY": null, "en-NZ": null, "en-PH": null, "en-SG": null, "en-US": null, "en-ZA": null }, "es": { "es-AR": null, "es-BO": null, "es-CL": null, "es-CO": null, "es-EC": null, "es-ES": null, "es-MX": null, "es-PE": null, "es-PY": null, "es-US": null, "es-UY": null, "es-VE": null }, "fi": { "fi-FI": null }, "fr": { "fr-BE": null, "fr-CA": null, "fr-FR": null, "fr-GF": null }, "hi": { "hi-IN": null }, "hu": { "hu-HU": null }, "id": { "id-ID": null }, "it": { "it-IT": null }, "ja": { "ja-JP": null }, "kn": { "kn-IN": null }, "ko": { "ko-KR": null }, "ml": { "ml-IN": null }, "mr": { "mr-IN": null }, "ms": { "ms-MY": null }, "nb": { "nb-NO": null }, "nl": { "nl-BE": null, "nl-NL": null, "nl-SR": null }, "pl": { "pl-PL": null }, "pt": { "pt-BR": null }, "ro": { "ro-RO": null }, "ru": { "ru-RU": null }, "sv": { "sv-SE": null }, "ta": { "ta-IN": null }, "te": { "te-IN": null }, "th": { "th-TH": null }, "tr": { "tr-TR": null }, "vi": { "vi-VN": null }, "zh": { "zh-Hans": { "zh-Hans-CN": null }, "zh-Hant": { "zh-Hant-HK": null, "zh-Hant-TW": null } } } }] }]
Tests:
Req
var dimensionsCopy = recursiveDeepCopy(dimensions);
json
var dimensionsCopy = jsonDeepCopy(dimensions);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Req
json
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 the provided benchmark and explain what's being tested, compared, and other considerations. **Benchmark Definition** The benchmark is defined by two scripts: `recursiveDeepCopy` and `jsonDeepCopy`. Both functions are used to create a copy of an object (in this case, the `dimensions` array). The main difference between the two functions lies in how they handle nested objects: * `recursiveDeepCopy`: This function uses recursion to iterate over each property of the object. If the value is an object itself, it calls itself recursively with that value. * `jsonDeepCopy`: This function uses JSON's built-in serialization and deserialization mechanism to create a copy of the object. **Individual Test Cases** There are two test cases: 1. **`req`**: This test case uses the `recursiveDeepCopy` function to create a copy of the `dimensions` array. 2. **`json`**: This test case uses the `jsonDeepCopy` function to create a copy of the `dimensions` array. **Latest Benchmark Result** The latest benchmark result shows the execution performance of both test cases on a Chrome 84 browser running on Linux: * **`req`**: The `recursiveDeepCopy` function executed approximately 267,037 times per second. * **`json`**: The `jsonDeepCopy` function executed approximately 35,720 times per second. **Comparison** The benchmark comparison highlights the performance difference between using recursion (in the `recursiveDeepCopy` function) and JSON-based serialization/deserialization (in the `jsonDeepCopy` function). It's clear that `recursiveDeepCopy` outperforms `jsonDeepCopy`. Here are some possible reasons for this performance difference: * **Recursion vs. Serialization**: Recursion can lead to a stack overflow if not implemented carefully, whereas JSON-based serialization/deserialization is generally more efficient and less prone to errors. * **Overhead of Function Calls**: The overhead of function calls can slow down `recursiveDeepCopy`, especially for large objects with many nested properties. **Other Considerations** When working with nested objects, consider the following: * **Memoization**: If you need to perform this operation frequently, consider memoizing the results of expensive function calls to avoid redundant computations. * **Object Cloning Strategies**: Depending on your specific use case, you might want to explore other object cloning strategies that balance performance and readability. I hope this explanation helps clarify what's being tested in this benchmark!
Related benchmarks:
Object Deep Copy
Object Deep Copy test
Object Deep Copy 2
Array Deep Copy 2 levels
Comments
Confirm delete:
Do you really want to delete benchmark?