<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 src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js'></script>
function recursiveDeepCopy(obj) {
return Object.keys(obj).reduce((v, d) => Object.assign(v, {
[d]: (obj[d].constructor === Object) ? recursiveDeepCopy(obj[d]) : obj[d]
}), {});
}
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function recursiveDeepCopyBabel(obj) {
return Object.keys(obj).reduce(function (v, d) {
return Object.assign(v, _defineProperty({}, 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
}
}
}
}]
}]
var dimensionsCopy = recursiveDeepCopy(dimensions);
var dimensionsCopy = jsonDeepCopy(dimensions);
var dimensionsCopy = _.cloneDeep(dimensions);
var dimensionsCopy = $.extend(true, {}, dimensions)
var dimensionsCopy = recursiveDeepCopyBabel(dimensions)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Recursive Deep Copy | |
JSON Deep Copy | |
lodash clone | |
jQuery extend | |
Recursive Deep Copy Babel |
Test name | Executions per second |
---|---|
Recursive Deep Copy | 260560.5 Ops/sec |
JSON Deep Copy | 26633.5 Ops/sec |
lodash clone | 13024.5 Ops/sec |
jQuery extend | 15142.2 Ops/sec |
Recursive Deep Copy Babel | 258145.5 Ops/sec |
I'll provide the answer without any extraneous text.
Index | RawUAString | Browser | DevicePlatform | OperatingSystem | ExecutionsPerSecond | TestName |
---|---|---|---|---|---|---|
0 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 260560.515625 | Recursive Deep Copy |
1 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 258145.453125 | Recursive Deep Copy Babel |
2 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 26633.482421875 | JSON Deep Copy |
3 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 15142.203125 | jQuery extend |
4 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 13024.537109375 | lodash clone |
Index | Benchmark Definition | Test Name |
---|---|---|
0 | var dimensionsCopy = recursiveDeepCopy(dimensions); | Recursive Deep Copy |
1 | var dimensionsCopy = jsonDeepCopy(dimensions); | JSON Deep Copy |
2 | var dimensionsCopy = _.cloneDeep(dimensions); | lodash clone |
3 | var dimensionsCopy = $.extend(true, {}, dimensions); | jQuery extend |
4 | var dimensionsCopy = recursiveDeepCopyBabel(dimensions); | Recursive Deep Copy Babel |
Index | RawUAString | Browser | DevicePlatform | OperatingSystem | ExecutionsPerSecond | TestName |
---|---|---|---|---|---|---|
0 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 260560.515625 | Recursive Deep Copy |
1 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 258145.453125 | Recursive Deep Copy Babel |
2 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 26633.482421875 | JSON Deep Copy |
3 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 15142.203125 | jQuery extend |
4 | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 | Chrome 96 | Desktop | Windows | 13024.537109375 | lodash clone |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
Please let me know if you'd like me to clarify any of these answers!