Skip to content

Instantly share code, notes, and snippets.

@trevnorris
Created November 7, 2016 22:10
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 trevnorris/93f0e45a3af4ae38edda316fc828c663 to your computer and use it in GitHub Desktop.
Save trevnorris/93f0e45a3af4ae38edda316fc828c663 to your computer and use it in GitHub Desktop.
quick comparison doing a loop of nextTick()'s using different calling methods
'use strict';
const print = process._rawDebug;
const ITER = 1e6;
var t = process.hrtime();
(function runner(i) {
if (i > ITER) return printTime();
// Slowest
//process.nextTick(() => runner(i + 1));
// Faster
process.nextTick(runner.bind(null, i + 1));
// Fastest
//process.nextTick(runner, i + 1);
})(0);
function printTime() {
t = process.hrtime(t);
print(((t[0] * 1e9 + t[1]) / ITER).toFixed(1) + ' ns/op');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment