Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
123132
(version: 0)
asa
Comparing performance of:
recursiveDeepCopy vs deepClone
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
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 deepClone(obj) { if (obj === null) return null; let clone = Object.assign({}, obj); Object.keys(clone).forEach( key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key]) ); if (Array.isArray(obj)) { clone.length = obj.length; return Array.from(clone); } return clone; }; 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:
recursiveDeepCopy
var dimensionsCopy = recursiveDeepCopy(dimensions);
deepClone
var dimensionsCopy = deepClone(dimensions);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
recursiveDeepCopy
deepClone
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, individual test cases, and latest benchmark result to provide an in-depth analysis. **Benchmark Definition** The benchmark definition is a JavaScript code that creates a copy of the `dimensions` object using two different functions: `recursiveDeepCopy` and `deepClone`. The benchmark defines the input data (`dimensions`) but not its initial state. This means that the benchmark relies on the caller to provide the initial value of `dimensions`, which may have an impact on the results. **Individual Test Cases** There are two individual test cases: 1. **recursiveDeepCopy**: This test case creates a copy of the `dimensions` object using the `recursiveDeepCopy` function. 2. **deepClone**: This test case creates a copy of the `dimensions` object using the `deepClone` function. Both functions are designed to create a deep copy of the input object, which means that all nested objects and arrays are recursively copied. **Latest Benchmark Result** The latest benchmark result provides performance data for both test cases: 1. **recursiveDeepCopy**: The average number of executions per second is 416854.90625. 2. **deepClone**: The average number of executions per second is 18366.529296875. These results indicate that the `recursiveDeepCopy` function is significantly faster than the `deepClone` function, likely due to its more efficient implementation or optimization. **Comparison and Analysis** Comparing the two test cases reveals some interesting insights: * The `recursiveDeepCopy` function is approximately 22x faster than the `deepClone` function. * The `recursiveDeepCopy` function is also slightly more efficient in terms of CPU usage, although this may not be noticeable without analyzing the detailed benchmark data. It's essential to note that these results are specific to the given test case and input data. In a real-world scenario, the performance differences between these functions might be less pronounced or even negligible, depending on the complexity and size of the input data. **Recommendations** Based on this analysis, I would recommend: 1. **Use `recursiveDeepCopy` for performance-critical code**: If you need to create deep copies of large objects or arrays frequently, consider using the `recursiveDeepCopy` function. 2. **Choose `deepClone` for simple use cases**: For simpler use cases where the input data is relatively small, the `deepClone` function might be sufficient and easier to implement. Remember that these recommendations are based on this specific benchmark definition and test case. You should always consider the trade-offs between performance, readability, and maintainability when selecting a deep copy implementation for your own codebase.
Related benchmarks:
Object Deep Copy with deep clone 34
Object Deep Copy with deep clone 344
Object Deep Copy with deep clone 3445123234
Object Deep Copy with deep clone 34451232342323
Comments
Confirm delete:
Do you really want to delete benchmark?