Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
RFDC clone vs clone-deep clone vs Lodash cloneDeep vs JSON Clone
(version: 0)
Comparing performance of: Lodash cloneDeep vs Json clone vs RFDC copy vs clone-deep copy
Comparing performance of:
RFDC clone vs LoDash cloneDeep clone vs Json clone vs clone-deep clone
Created:
5 years ago
by:
Guest
Jump to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
RFDC clone
LoDash cloneDeep clone
Json clone
clone-deep clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
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
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It appears that the data you provided is a collection of test results from a benchmarking tool, specifically for cloning various JavaScript objects. To summarize, the results show the performance of four different methods for cloning JavaScript objects: 1. **rfdc**: A library called rfdc (Recurse-Fast-Duplicate Clone) which provides a fast and efficient way to clone objects. 2. **LoDash**: A popular utility library that includes a `cloneDeep` function for deep cloning objects. 3. **JSON.parse(JSON.stringify())**: A built-in JavaScript method that can be used to clone objects by serializing them as JSON and then parsing the resulting string back into an object. 4. **clone-deep**: Another library that provides a `cloneDeep` function for deep cloning objects. The results show that rfdc has a significant performance advantage over LoDash, JSON.parse(JSON.stringify()), and clone-deep in terms of execution speed per second. Specifically: * rfdc: 520315.75 executions/second * LoDash: 212317.09375 executions/second * JSON.parse(JSON.stringify()): 108408.421875 executions/second * clone-deep: 18153.5546875 executions/second These results suggest that rfdc is a good choice for cloning JavaScript objects when performance is critical. However, it's worth noting that the LoDash and clone-deep libraries are still viable options if you prioritize ease of use or additional functionality over raw execution speed. Is there anything specific you'd like to know about these results or would you like me to extract any other insights from this data?
Related benchmarks:
RFDC clone vs Lodash cloneDeep vs JSON Clone vs recursive deep copy 3
klona vs Lodash cloneDeep
RFDC clone vs Lodash cloneDeep vs JSON Clone vs structured clone
RFDC clone vs Clone vs JSON Clone
Comments
Confirm delete:
Do you really want to delete benchmark?