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, timerLabel) { | |
console.time(timerLabel); | |
setTimeout(function() { | |
console.timeEnd(timerLabel); | |
}, milliSecondsToSleep); | |
} | |
console.time("Program"); | |
sleepFunction(1000, "FunctionCall1"); | |
sleepFunction(1000, "FunctionCall2"); |
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() { | |
let endTime = new Date().getTime(); | |
console.log("My job done in " + (endTime - startTime) + " ms"); | |
}, milliSecondsToSleep); | |
} | |
let startTime = new Date().getTime(); | |
sleepFunction(1000); |
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(); |
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
public class ExecutionTimeMeasurementExample { | |
public static void main(String[] args) throws InterruptedException { | |
long startTime = System.currentTimeMillis(); | |
sleepFunction(1000); | |
sleepFunction(1000); | |
long endTime = System.currentTimeMillis(); | |
System.out.println("Program took " + (endTime - startTime) + " ms to complete"); | |
} | |
private static void sleepFunction(int milliSecondsToSleep) throws InterruptedException { |
NewerOlder