Created
April 28, 2013 07:38
-
-
Save geNAZt/5476203 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 = {}, | |
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