Skip to content

Instantly share code, notes, and snippets.

@nanha
Forked from xk/nextTick.js
Created January 27, 2012 07:58
Show Gist options
  • Save nanha/1687711 to your computer and use it in GitHub Desktop.
Save nanha/1687711 to your computer and use it in GitHub Desktop.
nextTick.js
(function (ctr,t) {
function inc () { ctr++ }
function display (ntps,ntpsStr,i,lps,lpsStr,ratioStr) {
ntps= ctr*1e3/(Date.now()-t); //nextTicks per second
ntpsStr= ", nextTicksPerSecond: "+ ntps.toFixed(1);
ctr= 0, i= 100e6, t= Date.now();
while (i--) { inc() }
lps= ctr*1e3/(Date.now()-t); //loops per second
lpsStr= "loopsPerSecond: "+ lps.toFixed(1);
ratioStr= ", ratio: "+ (lps/ntps).toFixed(1)+ "x times faster";
console.log( lpsStr+ ntpsStr+ ratioStr );
ctr= 0, t= Date.now();
}
setInterval(display, 3e3);
t= Date.now();
(function ƒ () {
inc(), process.nextTick(ƒ);
})();
})(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment