Skip to content

Instantly share code, notes, and snippets.

@tankala
tankala / CoolWayToMeasureExecutionTime.js
Created April 21, 2018 10:25
Cool way to measure execution time in Node.js
var sleepFunction = function(milliSecondsToSleep, timerLabel) {
console.time(timerLabel);
setTimeout(function() {
console.timeEnd(timerLabel);
}, milliSecondsToSleep);
}
console.time("Program");
sleepFunction(1000, "FunctionCall1");
sleepFunction(1000, "FunctionCall2");
@tankala
tankala / CallBackWayToMeasureExecutionTime.js
Last active April 21, 2018 10:41
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);
@tankala
tankala / WrongWayToMeasureExecutionTime.js
Created April 21, 2018 10:00
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();
@tankala
tankala / ExecutionTimeMeasurementExample.java
Created April 21, 2018 09:48
Execution Time Measurement Example in Java
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 {