CSC 103 Lab Notes Week 7
Empirical Timing Programs



  1. Copy the following files from the CSC 103 examples directory into a working directory in your account:
    ListSortTimes.java,
    ListSortAndSearch.java.
    1. Compile and execute the ListSortTimes program.
      1. You will notice that the program bogs down as it executes.
      2. This is because it is running an O(N2) sorting algorithm on increasingly long lists.
    2. Inspect the program code to see how System.currentTimeMillis is used to record the execution time of the sortAndSearch.sort method.
    3. To save the output results on a file, run the program again as follows:
      ListSortTimes > sort.dat
      
      1. The '>' operator redirects the standard output of the program to the file named sort.dat.
      2. You can use this form of redirection to send the standard output of any Java program to a file.

  2. Once the ListSortTimes program has finished, run the program gnuplot from the command line of a standard terminal.
    1. gnuplot will respond with the following message on the terminal:
              G N U P L O T
              Unix version 3.7
              patchlevel 1
              last modified Fri Oct 22 18:00:00 BST 1999
      
              Copyright(C) 1986 - 1993, 1998, 1999
              Thomas Williams, Colin Kelley and many others
      
              Type `help` to access the on-line reference manual
              The gnuplot FAQ is available from
              <http://www.ucc.ie/gnuplot/gnuplot-faq.html>
      
              Send comments and requests for help to <info-gnuplot@dartmouth.edu>
              Send bugs, suggestions and mods to <bug-gnuplot@dartmouth.edu>
      
      
      Terminal type set to 'x11'
      gnuplot>
      
    2. After the gnuplot> prompt, enter the command:
      plot 'sort.dat'
      
    3. gnuplot will respond by displaying a window that looks like this:



  3. From another terminal window, run the program xv.
    1. xv will respond by displaying the following window:



    2. Click the right mouse button anywhere in this display window, whereupon xv will display another window that looks like this:



    3. Click on the "Grab" button in the xv controls window; xv will display the following window:



    4. If there are any xv windows covering any part of the gnuplot graph window, move them over so the gnuplot window is fully exposed.
    5. Click the "Grab" button in the latest xv window, then single click with the left mouse anywhere inside the gnuplot window.
      1. This action will cause xv to acquire the gnuplot window image, which it will display in its original window.
      2. If you want want to acquire the gnuplot image without the surrounding window banner, use the middle mouse button to drag around the portion of the image you want to acquire. (If you didn't see this demonstrated in lab, ask Fisher to show you how to do it.)
    6. You can now save the acquired image as a GIF or JPEG file, by pressing the "Save" button in the xv controls.
      1. xv displays the following window:



      2. Saving as a GIF image is the default; to do so, type the name of the file in the "Save file:" edit box and press "Ok".
      3. To save as a JPEG, select it under the "Format:" pulldown menu.

  4. You can include a GIF or JPEG image in a java program as illustrated in the ListSortTimes example.
    1. See the source program for the format of the HTML img command.
    2. This is the form that your hand-in for Assignment 4 will use.




index | lectures | labs | handouts | examples | assignments | solutions | doc | grades | help