// Program to show millisecond-accurate timing using Date().

import java.util.Date;

public class TestTime {
    public static void main(String [] args)
    {
	if ( args.length != 1) {
	    System.out.println("Usage: TestTime <loopcount>");
	    return;
	}
	int n = Integer.parseInt(args[0]);

	Date time1 = new Date();  // captures time before loop

	long sum = 0;
	for (int i=0; i< n; i++)  // loop to time
	    sum = sum + i;

	Date time2 = new Date();  // captures time after loop

	// compute difference = # milliseconds of elapsed time
	long deltaTime = time2.getTime() - time1.getTime();

	System.out.println("loop took " + deltaTime + " ms");
    }
}
