Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object Deep Copy with deep clone 3445123234
(version: 0)
Produce a deep copy of a Javascript object where nested objects are not simply references to the originals.
Comparing performance of:
Recursive Deep Copy vs JSON Deep Copy vs lodash clone vs deepclone vs Recursive Deep Copy 2
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.js"></script> <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 recursiveDeepCopy2(obj) { let result = Array.isArray(obj) ? [] : {}; const keys = Object.keys(result); const length = keys.length; for (let i = length; i > 0; i--) { let key = keys[i]; result[key] = typeof obj[key] === 'object' ? recursiveDeepCopy2(obj[key]) : obj[key]; } return result; } function deepClone(object) { let result; let i; let l; if (typeof object !== 'object') { return object; } if (!object) { return object; } if (object.constructor === Array) { result = []; l = object.length; for (i = 0; i < l; i++) { result[i] = deepClone(object[i]); } return result; } result = {}; for (i in object) { result[i] = deepClone(object[i]); } return result; } 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:
Recursive Deep Copy
var dimensionsCopy = recursiveDeepCopy(dimensions);
JSON Deep Copy
var dimensionsCopy = jsonDeepCopy(dimensions);
lodash clone
var dimensionsCopy = _.cloneDeep(dimensions);
deepclone
var dimensionsCopy = deepClone(dimensions);
Recursive Deep Copy 2
var dimensionsCopy = recursiveDeepCopy2(dimensions);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Recursive Deep Copy
JSON Deep Copy
lodash clone
deepclone
Recursive Deep Copy 2
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):
It looks like we're dealing with a complex scenario involving benchmarking and comparison of various JavaScript libraries for JSON and object deep copying. To provide a helpful response, I'll need to break down the provided information into manageable parts: 1. **Benchmark Results**: * These are test cases that measure the execution speed of different functions for deep copying JavaScript objects. * Each test case has a "RawUAString" field indicating the browser and device used for testing. * The "ExecutionsPerSecond" value represents the number of executions per second for each test case. 2. **Benchmark Definitions**: * These are code snippets that demonstrate how to perform deep copying using different libraries (e.g., `recursiveDeepCopy`, `jsonDeepCopy`, `_`, and `deepClone`). 3. **Html Preparation Code**: * This is a snippet of HTML code that includes two script tags, which likely load the Lodash library and a Babel minification script. 4. **Individual Test Cases**: * These are individual benchmark test cases with their respective definitions, test names, and benchmark results. Given this information, I'll provide some general insights and potential next steps: 1. Analyze the benchmark results: By examining the "ExecutionsPerSecond" values for each test case, we can determine which function performs best in terms of speed. 2. Compare the implementations: A closer look at the code snippets provided for each implementation (e.g., `recursiveDeepCopy`, `jsonDeepCopy`, `_`, and `deepClone`) will help us understand their underlying logic and potential differences. 3. Identify performance bottlenecks: By reviewing the benchmark results, we may be able to identify areas where one library outperforms another in terms of execution speed. To proceed further, I'd need more specific questions or requests regarding the analysis, such as: * Which function performs best across all test cases? * Are there any notable differences between the implementations? * Are there any performance bottlenecks that can be improved? Please let me know how you'd like to proceed, and I'll do my best to assist you!
Related benchmarks:
Object Deep Copy with deep clone 3
Object Deep Copy with deep clone 34
Object Deep Copy with deep clone 344
Object Deep Copy with deep clone 34451232342323
Comments
Confirm delete:
Do you really want to delete benchmark?