Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created April 28, 2013 07:38
Show Gist options
  • Save geNAZt/5476203 to your computer and use it in GitHub Desktop.
Save geNAZt/5476203 to your computer and use it in GitHub Desktop.
var obj = {},
needed = 1024*1024;
for(i = 0; i < needed; i++) {
obj[i] = "avx";
}
function forLoopTest() {
var start = process.hrtime();
setTimeout(function() {
var end = process.hrtime(start);
console.log("for: Blocked time: ", end[1] / 1e9, " ms");
process.nextTick(function() {
foreachLoopTest();
});
}, 1000);
setInterval(function() {
for(var key in obj) {
if(obj.hasOwnProperty(key)) {
//console.log(key);
}
}
}, 5);
}
function foreachLoopTest() {
var start = process.hrtime();
setTimeout(function() {
var end = process.hrtime(start);
console.log("foreach: Blocked time: ", end[1] / 1e9, " ms");
process.nextTick(function() {
process.exit(0);
});
}, 1000);
setInterval(function() {
Object.keys(obj).forEach(function(value) {
});
}, 5);
}
forLoopTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment