Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
deep clone
Compare the new ES6 spread operator with the traditional concat() method
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
JSON parse
1616606.6 Ops/sec
_.deepClone
0.0 Ops/sec
fast-clone
335522.9 Ops/sec
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script> <script src="https://cdn.rawgit.com/ivolovikov/fastest-clone/master/index.js"></script>
Script Preparation code:
var source = {a:1,b:1,c:1,d:1,e:1,f:1,g:1,h:{a:-1,b:1,c:1,d:1,e:1,f:1,g:1}}; //var source = {a:1}; //var CloneFactory = FastClone.factory(source); function clone(value) { var type = typeof value; switch (type) { case 'object': // null and undefined if (value == null) { return value; } var result = void 0; if (value instanceof Date) { result = new Date(); result.setTime(value.getTime()); return result; } else if (value instanceof RegExp) { result = newRegExp(value); return result; } result = JSON.parse(JSON.stringify(value)); fixTypes(value, result); return result; default: return value; } } function fixPropertyValue(original, copy, key) { var originalValue = original[key]; var originalType = typeof originalValue; switch (originalType) { case 'object': if (originalValue instanceof Date) { var newValue = new Date(); newValue.setTime(originalValue.getTime()); copy[key] = newValue; } else if (originalValue instanceof RegExp) { copy[key] = newRegExp(originalValue); } else if (originalValue == null) { copy[key] = originalValue; } else { fixTypes(originalValue, copy[key]); } break; case 'number': if (isNaN(originalValue)) { copy[key] = NaN; } else if (originalValue == Infinity) { copy[key] = Infinity; } break; default: break; } } function fixTypes(original, copy) { if (original instanceof Array) { for (var index = 0; index < original.length; index++) { fixPropertyValue(original, copy, index); } } else { var keys = Object.getOwnPropertyNames(original); keys.forEach(function (key) { fixPropertyValue(original, copy, key); }); } } function newRegExp(value) { var regexpText = String(value); var slashIndex = regexpText.lastIndexOf('/'); return new RegExp(regexpText.slice(1, slashIndex), regexpText.slice(slashIndex + 1)); }
Tests:
JSON parse
var objects = [{ 'a': 1 }, { 'b': 2, c: 3, d: 4 }, {c:3}, 4, 5, 6 ,'hello']; //var objects = {a:1,b:1,c:1,d:1,e:1,f:1,g:1,h:{a:-1,b:1,c:1,d:1,e:1,f:1,g:1}}; var deep = JSON.parse(JSON.stringify(objects));
_.deepClone
var objects = [{ 'a': 1 }, { 'b': 2, c: 3, d: 4 }, {c:3}, 4, 5, 6 ,'hello']; //var objects = {a:1,b:1,c:1,d:1,e:1,f:1,g:1,h:{a:-1,b:1,c:1,d:1,e:1,f:1,g:1}}; var deep = _.cloneDeep(objects);
fast-clone
//var objects = {a:1,b:1,c:1,d:1,e:1,f:1,g:1,h:{a:-1,b:1,c:1,d:1,e:1,f:1,g:1}}; var objects = [{ 'a': 1 }, { 'b': 2, c: 3, d: 4 }, {c:3}, 4, 5, 6 ,'hello']; var deep = clone(objects);