Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object Deep Copy with
(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 c7x43t
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:
// deep copy: // String, Number, undefined, null, Set, Map, typed Array, Object, Boolean, RegExp, Date, ArrayBuffer // Functions, Properties of types: (Primitive, Symbol) // shallow copy (by reference): // WeakMap, WeakSet, Symbol function deepCopy(o) { if ((typeof o !== "object" || o === null) && !(o instanceof Function)) return o; // fast obj/null test let n, keys; const c = o.constructor; if (o[Symbol.iterator] instanceof Function) { // fast array test // Map and Set have no length property so they will be correctly constructed const l = o.length; n = (new c(l)); switch (c) { case Set: for (let e of o) n.add(deepCopy(e)); break; case Map: for (let [key, value] of o) n.set(key, deepCopy(value)); break; } for (let i of Object.keys(o)) n[i] = deepCopy(o[i]); } else { if (c !== Object) { switch (c) { case Function: let str = o.toString(); if(/ \[native code\] /.exec(str) === null){ let args=/^.*?\((.*?)\)/.exec(str)[1];//.split(/,/); let func=/^.*?{(.*)}/.exec(str)[1]; n=new c(args,func); }else{ n=o; } break; case RegExp: n = new c(o.valueOf()); break; case Date: n = new c(o); break; case ArrayBuffer: n = new c((new Int8Array(o)).length); break; default: n = o; } keys = Object.keys(o); } else { n = {}; keys = Object.getOwnPropertyNames(o); } for (let i of keys) n[i] = deepCopy(o[i]); } for (let i of Object.getOwnPropertySymbols(o)) n[i] = deepCopy(o[i]); return n; } 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:
Recursive Deep Copy
var dimensionsCopy = recursiveDeepCopy(dimensions);
JSON Deep Copy
var dimensionsCopy = jsonDeepCopy(dimensions);
lodash clone
var dimensionsCopy = _.cloneDeep(dimensions);
c7x43t
var dimensionsCopy = deepCopy(dimensions);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Recursive Deep Copy
JSON Deep Copy
lodash clone
c7x43t
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Browser/OS:
Firefox 115 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Recursive Deep Copy
2222321.2 Ops/sec
JSON Deep Copy
54111.2 Ops/sec
lodash clone
25940.3 Ops/sec
c7x43t
62696.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll do my best to answer your questions. It seems like you provided a JSON string with some test data, including benchmark results and individual test cases. You also mentioned that the test names are "Recursive Deep Copy", "JSON Deep Copy", "lodash clone", and "c7x43t". To provide an accurate answer, I would need more information about what you're trying to achieve or ask. However, based on the provided data, here's a summary: 1. You have three JSON objects: * `dimensions`: an object with nested properties (e.g., `ml-IN`, `mr-IN`, etc.) * `Html Preparation Code`: a string containing HTML script tags * `Individual test cases`: an array of objects with "Benchmark Definition" and "Test Name" properties 2. The benchmark results show the execution times for each test case on Firefox 115: * Recursive Deep Copy: 2222321.25 executions per second * JSON Deep Copy: 54111.2265625 executions per second * lodash clone: 25940.3125 executions per second * c7x43t: 62696.43359375 executions per second If you could provide more context or clarify what you'd like to know or achieve with this data, I'll do my best to help!
Related benchmarks:
Object Deep Copy with deep clone
Object Deep Copy with deep clone 3445123234
Object Deep Copy test 20240213-2
Object.assign vs. JSON String/Parse vs deepclone
Comments
Confirm delete:
Do you really want to delete benchmark?