Created
September 18, 2013 21:31
-
-
Save keis/6616035 to your computer and use it in GitHub Desktop.
try to figure out how often we yield for IO / other callbacks
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
function yielding() { | |
var stop = false, | |
stamp = (new Date()).getTime(), | |
count = 0, | |
clear; | |
function tick() { | |
if (!stop) { | |
count++; | |
clear = setImmediate(tick); | |
} | |
} | |
setImmediate(tick); | |
return { | |
stop: function () { | |
var duration = ((new Date()).getTime() - stamp) / 1000.0, | |
freq = count / duration; | |
stop = true; | |
clearImmediate(clear); | |
console.log('yielded ' + count + ' times in ' + duration + ' seconds. ' + freq + ' y/s') | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment