Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
RFDC clone vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
Comparing performance of: Lodash cloneDeep vs Json clone vs RFDC copy vs clone-deep copy
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser:
Firefox 140
Operating system:
Windows
Device Platform:
Desktop
Date tested:
10 months ago
Test name
Executions per second
RFDC clone
200491.5 Ops/sec
LoDash cloneDeep clone
43608.7 Ops/sec
Json clone
147375.1 Ops/sec
clone-deep clone
47857.5 Ops/sec
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/rfdc@1.1.4/index.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>
Script Preparation code:
var sampleObject = [{ "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" }, { "id": "1003", "type": "Blueberry" }, { "id": "1004", "type": "Devil's Food" } ] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5007", "type": "Powdered Sugar" }, { "id": "5006", "type": "Chocolate with Sprinkles" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0002", "type": "donut", "name": "Raised", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0003", "type": "donut", "name": "Old Fashioned", "ppu": 0.55, "batters": { "batter": [{ "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" } ] }, "topping": [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] } ]; var myCopy = null; // minified clone-deep var toString=Object.prototype.toString;function isObject(r){return"[object Object]"===Object.prototype.toString.call(r)}function isPlainObject(r){var e,t;return!1!==isObject(r)&&(void 0===(e=r.constructor)||!1!==isObject(t=e.prototype)&&!1!==t.hasOwnProperty("isPrototypeOf"))}function kindOf(r){if(void 0===r)return"undefined";if(null===r)return"null";var e=typeof r;if("boolean"===e)return"boolean";if("string"===e)return"string";if("number"===e)return"number";if("symbol"===e)return"symbol";if("function"===e)return isGeneratorFn(r)?"generatorfunction":"function";if(isArray(r))return"array";if(isBuffer(r))return"buffer";if(isArguments(r))return"arguments";if(isDate(r))return"date";if(isError(r))return"error";if(isRegexp(r))return"regexp";switch(ctorName(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(isGeneratorObj(r))return"generator";switch(e=toString.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return e.slice(8,-1).toLowerCase().replace(/\s/g,"")}function ctorName(r){return"function"==typeof r.constructor?r.constructor.name:null}function isArray(r){return Array.isArray?Array.isArray(r):r instanceof Array}function isError(r){return r instanceof Error||"string"==typeof r.message&&r.constructor&&"number"==typeof r.constructor.stackTraceLimit}function isDate(r){return r instanceof Date||"function"==typeof r.toDateString&&"function"==typeof r.getDate&&"function"==typeof r.setDate}function isRegexp(r){return r instanceof RegExp||"string"==typeof r.flags&&"boolean"==typeof r.ignoreCase&&"boolean"==typeof r.multiline&&"boolean"==typeof r.global}function isGeneratorFn(r,e){return"GeneratorFunction"===ctorName(r)}function isGeneratorObj(r){return"function"==typeof r.throw&&"function"==typeof r.return&&"function"==typeof r.next}function isArguments(r){try{if("number"==typeof r.length&&"function"==typeof r.callee)return!0}catch(r){if(-1!==r.message.indexOf("callee"))return!0}return!1}function isBuffer(r){return!(!r.constructor||"function"!=typeof r.constructor.isBuffer)&&r.constructor.isBuffer(r)}function cloneDeep(r,e){switch(kindOf(r)){case"object":return cloneObjectDeep(r,e);case"array":return cloneArrayDeep(r,e);default:return clone(r)}}function cloneObjectDeep(r,e){if("function"==typeof e)return e(r);if(e||isPlainObject(r)){const t=new r.constructor;for(let n in r)t[n]=cloneDeep(r[n],e);return t}return r}function cloneArrayDeep(r,e){const t=new r.constructor(r.length);for(let n=0;n<r.length;n++)t[n]=cloneDeep(r[n],e);return t}const valueOf=Symbol.prototype.valueOf;function clone(r,e){switch(kindOf(r)){case"array":return r.slice();case"object":return Object.assign({},r);case"date":return new r.constructor(Number(r));case"map":return new Map(r);case"set":return new Set(r);case"buffer":return cloneBuffer(r);case"symbol":return cloneSymbol(r);case"arraybuffer":return cloneArrayBuffer(r);case"float32array":case"float64array":case"int16array":case"int32array":case"int8array":case"uint16array":case"uint32array":case"uint8clampedarray":case"uint8array":return cloneTypedArray(r);case"regexp":return cloneRegExp(r);case"error":return Object.create(r);default:return r}}function cloneRegExp(r){const e=void 0!==r.flags?r.flags:/\w+$/.exec(r)||void 0,t=new r.constructor(r.source,e);return t.lastIndex=r.lastIndex,t}function cloneArrayBuffer(r){const e=new r.constructor(r.byteLength);return new Uint8Array(e).set(new Uint8Array(r)),e}function cloneTypedArray(r,e){return new r.constructor(r.buffer,r.byteOffset,r.length)}function cloneBuffer(r){const e=r.length,t=Buffer.allocUnsafe?Buffer.allocUnsafe(e):Buffer.from(e);return r.copy(t),t}function cloneSymbol(r){return valueOf?Object(valueOf.call(r)):{}}
Tests:
RFDC clone
var clone = rfdc(); myCopy = clone(sampleObject);
LoDash cloneDeep clone
myCopy = _.cloneDeep(sampleObject);
Json clone
myCopy = JSON.parse(JSON.stringify(sampleObject));
clone-deep clone
myCopy = cloneDeep(sampleObject);