Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created August 22, 2017 03:36
Show Gist options
  • Save alextanhongpin/c839b063e07712272ebcff63f4a33158 to your computer and use it in GitHub Desktop.
Save alextanhongpin/c839b063e07712272ebcff63f4a33158 to your computer and use it in GitHub Desktop.
Precise time calculation in nodejs
var start = new Date();
var hrstart = process.hrtime();
setTimeout(function (argument) {
// execution time simulated with setTimeout function
var end = new Date() - start,
hrend = process.hrtime(hrstart);
console.info("Execution time: %dms", end);
console.info("Execution time (hr): %ds %dms", hrend[0], hrend[1]/1000000);
}, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment