Created
April 21, 2018 10:00
-
-
Save tankala/c27865b892bd98b3e1ec90c6be6a1d68 to your computer and use it in GitHub Desktop.
Wrong way to measure execution time in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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