Last active
November 13, 2017 15:55
-
-
Save PocasPedro/ca59f8bcf0a3d5ba3929e2d5220d5c5a to your computer and use it in GitHub Desktop.
Java Fundamentals for Kids - Exercise 25
This file contains 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
import java.util.concurrent.TimeUnit; | |
import java.util.Date; | |
import java.lang.Math; | |
/** | |
Program that runs a method for 3 seconds and calculates the time spent doing that execution | |
*/ | |
public class ExecutionTime { | |
public static void main(String[] args) { | |
Date initialDate = new Date(); | |
doSomething(); | |
Date laterDate = new Date(); | |
long timespent; | |
timespent = Math.abs(laterDate.getTime()-initialDate.getTime())/1000; | |
System.out.println("The time consumed by this method was : " + timespent + " seconds!"); | |
} | |
public static void doSomething() { | |
System.out.println("Doing something ..."); | |
try{ | |
TimeUnit.SECONDS.sleep(3); | |
} catch (InterruptedException e) { | |
System.out.println("Some Error"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment