Created
May 11, 2013 07:17
-
-
Save geNAZt/5559184 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var obj = {}; | |
var arr = []; | |
for(var i=0; i < 1280000; i++) { | |
obj[i] = "a"; | |
arr.push("a"); | |
} | |
var start = process.hrtime(); | |
for(var x in obj) { | |
if(obj.hasOwnProperty(x)) { | |
} | |
}; | |
console.log("obj - for: " + process.hrtime(start)[1] / 1e6); | |
var start = process.hrtime(); | |
Object.keys(obj).forEach(function(v) { | |
}); | |
console.log("obj - forEach: " + process.hrtime(start)[1] / 1e6); | |
var start = process.hrtime(); | |
for(var y = 0; y < arr.length; y++ ) { | |
}; | |
console.log("arr - for: " + process.hrtime(start)[1] / 1e6); | |
var start = process.hrtime(); | |
arr.forEach(function(v) { | |
}); | |
console.log("arr - forEach: " + process.hrtime(start)[1] / 1e6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//Output
obj - for: 564.066452
obj - forEach: 499.227533
arr - for: 5.746904
arr - forEach: 68.975154