import rebelsky.util.IntegerArrayAlgorithms;
import rebelsky.io.SimpleOutput;

/**
 * A simple timer for one of the sorting algorithms provided by
 * rebelsky.util.IntegerArrayAlgorithms.
 *
 * @author Samuel A. Rebelsky
 * @version 1.0 of February 1998
 */
public class SortTimer
{
  /**
   * Sort 1000 things and report on the time it took.  Crash and
   * burn when one of the methods I use crashes and burns.
   */
  public static void main(String[] args)
    throws Exception
  {
    // The size of the arrays we'll be creating.
    int size = 500;
    // The array we'll be working with.
    int[] arr;
    // A sorted version of that array.
    int[] sorted;
    // How to print output.
    SimpleOutput out = new SimpleOutput();
    // The time (wall clock) before the sorting starts.
    long start;
    // The time (wall clock) after sorting ends.
    long finish;

    // Generate a "random" array of the appropriate size
    arr = IntegerArrayAlgorithms.random(size);
    // Get the current time (in milliseconds since some weird date).
    start = System.currentTimeMillis();
    // Sort!
    sorted = IntegerArrayAlgorithms.bubbleSort(arr);
    // Get the current time
    finish = System.currentTimeMillis();
    // The elapsed time is the difference between the two times.
    System.out.println("Sorting " + size + " elements took " 
      + (finish-start) + " milliseconds");
  } // main
} // SortTimer

