Clone deep vs Spread vs Stringify
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.2 Safari/605.1.15
Test name
Executions per second
Lodash
473127.2 Ops/sec
Spread
834412.8 Ops/sec
Stringify
304034.8 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var MyObject = { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } }; var myCopy = null;
Tests:
Lodash
myCopy = _.cloneDeep(MyObject);
Spread
myCopy = { ...MyObject }
Stringify
myCopy = JSON.parse(JSON.stringify(MyObject))
Open this result on MeasureThat.net