Skip to content

Instantly share code, notes, and snippets.

@ifraixedes
Created October 6, 2014 12:32
Show Gist options
  • Save ifraixedes/224f3b77878a87d6b79b to your computer and use it in GitHub Desktop.
Save ifraixedes/224f3b77878a87d6b79b to your computer and use it in GitHub Desktop.
Execution diferential time between cloning with JSON and locash#cloneDeep
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