title: Timing quick sort algorithm
body: <p>Hey I seem to be having a problem trying to implement some Java quick sort code over an array of 10,000 random numbers. I have a text file containing the numbers which are placed into an array, which is then passed to the sorting algorithm to be sorted. My aim is to time how long it takes to time the sorting increasing the numbers sorted each time using the timing loop I have. But for some reason using this code gives me a curved graph instead of a straight linear line. I know the timing loop and array code work fine so there seems to be a problem with the sorting code but can't seem to find anything! Any help is greatly appreciated thanks! </p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  public class Quicksort {
  
  public static void main(String args[]) throws IOException {
  //Import the random integer text file into an integer array
  File fil = new File("randomASC.txt");
  FileReader inputFil = new FileReader(fil);
  int [] myarray = new int [10000];
  Scanner in = new Scanner(inputFil);
  
  for(int q = 0; q &lt; myarray.length; q++)
  {
    myarray[q] = in.nextInt();
  }
  in.close();
  
  
  
  for (int n = 100; n &lt; 10000; n += 100) { 
  long total = 0;
  for (int r = 0; r &lt; 10; ++r) {  
    long start = System.nanoTime ();    
        quickSort(myarray,0,n-1);
        total += System.nanoTime() - start;
      }
    System.out.println (n + "," + (double)total / 10.0);
  } 
  }
  
   public static void quickSort(int[] a, int p, int r)
  {
      if(p&lt;r)
      {
          int q=partition(a,p,r);
          quickSort(a,p,q);
          quickSort(a,q+1,r);
      }
  }
  
  private static int partition(int[] a, int p, int r) {
  
      int x = a[p];
      int i = p-1 ;
      int j = r+1 ;
  
      while (true) {
          i++;
          while ( i&lt; r &amp;&amp; a[i] &lt; x)
              i++;
          j--;
          while (j&gt;p &amp;&amp; a[j] &gt; x)
              j--;
  
          if (i &lt; j)
              swap(a, i, j);
          else
              return j;
      }
  }
  
  private static void swap(int[] a, int i, int j) {
      // TODO Auto-generated method stub
      int temp = a[i];
      a[i] = a[j];
      a[j] = temp;
  }
  }
  </code></pre>