Skip to content

Instantly share code, notes, and snippets.

@tankala
Created April 21, 2018 10:00
Show Gist options
  • Save tankala/c27865b892bd98b3e1ec90c6be6a1d68 to your computer and use it in GitHub Desktop.
Save tankala/c27865b892bd98b3e1ec90c6be6a1d68 to your computer and use it in GitHub Desktop.
Wrong way to measure execution time in Node.js
var sleepFunction = function(milliSecondsToSleep) {
let startTime = new Date().getTime();
setTimeout(function() {
console.log("Dummy CallBack");
}, milliSecondsToSleep);
let endTime = new Date().getTime();
console.log("My job done in " + (endTime - startTime) + " ms");
}
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