Skip to content

Instantly share code, notes, and snippets.

@eit
Forked from VanDalkvist/execution-time.js
Created September 17, 2020 16:36
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 eit/10cc28e41aa69b1d8c69f3f9d6de8167 to your computer and use it in GitHub Desktop.
Save eit/10cc28e41aa69b1d8c69f3f9d6de8167 to your computer and use it in GitHub Desktop.
How to Measure Execution Time in Node.js
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);
// Execution time: 1ms
// Execution time (hr): 0s 1.025075ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment