Skip to content

Instantly share code, notes, and snippets.

@tristanls
Forked from xk/nextTick.js
Created December 22, 2011 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tristanls/1512111 to your computer and use it in GitHub Desktop.
Save tristanls/1512111 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