Skip to content

Instantly share code, notes, and snippets.

@keis
Created September 18, 2013 21:31
Show Gist options
  • Save keis/6616035 to your computer and use it in GitHub Desktop.
Save keis/6616035 to your computer and use it in GitHub Desktop.
try to figure out how often we yield for IO / other callbacks
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