Created
October 13, 2016 10:43
-
-
Save andrew-aladev/ca150b8ccbbac539ee5d82d8c1c0c25b to your computer and use it in GitHub Desktop.
setImmediate overhead
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 getOverhead() { | |
return new Promise(function (resolve) { | |
var overhead = [0, 0]; | |
var isCompleted = false; | |
function handler() { | |
if (isCompleted) { | |
resolve(overhead[0] + overhead[1] / 1e9); | |
return; | |
} | |
var overheadStart = process.hrtime(); | |
setImmediate(function () { | |
var diff = process.hrtime(overheadStart); | |
overhead[0] += diff[0]; | |
overhead[1] += diff[1]; | |
handler(); | |
}); | |
} | |
handler(); | |
setTimeout(function () { | |
isCompleted = true; | |
}, 10000); | |
}); | |
} | |
getOverhead() | |
.then(function (overhead) { | |
console.log('overhead', overhead); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment