Skip to content

Instantly share code, notes, and snippets.

@tankala
Last active April 21, 2018 10:41
Show Gist options
  • Save tankala/5aafcf204855e5bca53954588c4f0b89 to your computer and use it in GitHub Desktop.
Save tankala/5aafcf204855e5bca53954588c4f0b89 to your computer and use it in GitHub Desktop.
CallBack way to measure execution time in Node.js
var sleepFunction = function(milliSecondsToSleep) {
let startTime = new Date().getTime();
setTimeout(function() {
let endTime = new Date().getTime();
console.log("My job done in " + (endTime - startTime) + " ms");
}, milliSecondsToSleep);
}
let startTime = new Date().getTime();
sleepFunction(1000);
sleepFunction(1000);
let endTime = new Date().getTime();
console.log("Program took " + (endTime - startTime) + " ms to complete");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment