Created
October 6, 2014 12:32
-
-
Save ifraixedes/224f3b77878a87d6b79b to your computer and use it in GitHub Desktop.
Execution diferential time between cloning with JSON and locash#cloneDeep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
const times = 1000000; | |
const srcObj = { | |
_string: 'hey you', | |
_array: [1, 2, 3, 4, 5, 6], | |
_obj: { | |
_string: 'hey you', | |
_array: [1, 2, 3, 4, 5, 6] | |
} | |
}; | |
function jsonCloning(obj) { | |
return JSON.parse(JSON.stringify(obj)); | |
} | |
function _cloning(obj) { | |
return _.cloneDeep(obj); | |
} | |
var i; | |
var startTime; | |
startTime = Date.now(); | |
for (var i = 0; i < times; i++) { | |
jsonCloning(srcObj); | |
} | |
console.info(Date.now() - startTime); | |
startTime = Date.now(); | |
for (var i = 0; i < times; i++) { | |
_cloning(srcObj); | |
} | |
console.info(Date.now() - startTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment