import java.util.Date; /** * This program demonstrates the runtimes of various constructs. * * @author Matt Boutell. * Created Sep 2, 2006. */ public class Runtime { private static double d = 0; /** * Execution always starts in main(). * * @param args */ public static void main(String[] args) { // Experiment with various values of n. // They'll need to be fairly large to produce times // over 0 milliseconds. double num = 1E6; Date start = new Date(); // Insert code here that you want to time. // Code that you want to time is above here. Date end = new Date(); // Computes and displays elapsed time in milliseconds long elapsedTime = end.getTime()-start.getTime(); System.out.println("Done for n = " + num); System.out.println("Time = " + elapsedTime); int theBiggestNumberYouveEverSeen = 17; theBiggestNumberYouveEverSeen++; } /** * Computing the sum of the harmonic series * just to waste some time in calling the method. * * @param i */ private static void f(double i) { d = d + 1.0/i; } }