deep clone - lodash vs ramda vs json
Date tested:
one year ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Test name
Executions per second
lodash - cloneDeep
1469522.6 Ops/sec
json - parse/stringify
687984.6 Ops/sec
ramda - clone
2148334.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 src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var obj = { author: 'Jason Carmona', fieldNumber: 112050642, nestedObject: { funFact1: 'You burn more calories sleeping than you do watching television', funFact2: 'The average person spends 6 months of their lifetime waiting on a red light to turn green', funFact3: 'There are more possible iterations of a game of chess than there are atoms in the known universe', funFact4: 'Coca-Cola would be green if coloring wasn’t added to it', funFact5: 'You cannot snore and dream at the same time' } }; var objCopy = null;
Tests:
lodash - cloneDeep
objCopy = _.cloneDeep(obj);
json - parse/stringify
objCopy = JSON.parse(JSON.stringify(obj));
ramda - clone
objCopy = R.clone(obj);
Open this result on MeasureThat.net