title: Second method call takes far less time than the first
body: <p>I'm trying to speed up the startup for my program, and noticed I had a method that was acting a little strange. The program itself is a Lightweight Java Game Library application that reads in points from a file, and renders them. The method of note is the method that reads from the file.</p>
  
  <p>What's curious about the method is I call it twice during my tests, where the first call takes 2837ms to complete, and the second only takes 1704ms.</p>
  
  <p>The difference between the two calls are minimal. The difference is the second call reads through half the file before beginning any operations with the file, while the first skips a single line before starting.</p>
  
  <p>This is the method in question:</p>
  
  <pre><code>private void initData(final int type) throws IOException {
      final List&lt;Vertex&gt; top = new ArrayList&lt;Vertex&gt;();
      final List&lt;Vertex&gt; bot = new ArrayList&lt;Vertex&gt;();
      final BufferedReader input = new BufferedReader(new FileReader(location));
      if(type == 1) {
          while (!input.readLine().contains("lens"));
      } else {
          input.readLine();
      }
      while (input.ready()) {
          final Scanner in = new Scanner(input.readLine());
          while (in.hasNextFloat()) {
              final float x = in.nextFloat();
              final float y = in.nextFloat();
              top.add(new Vertex(x, y, in.nextFloat()));
              bot.add(new Vertex(x, y, in.nextFloat()));
              in.nextFloat();
          }
          if ((in.findInLine("[lens]") != null)
                  || (in.findInLine("[thin]") != null)
                  || (in.findInLine("[thick]") != null)
                  || (in.findInLine("[end]") != null)) {
              break;
          }
      }
      input.close();
      final long start = Diagnostics.getCurrentTime();
      mergeAndSort(top, bot);
      System.out.println("Sort: " + (Diagnostics.getCurrentTime() - start));
  }
  </code></pre>
  
  <p>The output I get from this is:</p>
  
  <pre><code>Sort: 15
  Initializing: 2836
  Sort: 4
  Initializing: 1704
  Reading info: 27
  </code></pre>
  
  <p>Where all numbers are in milliseconds. You'll notice the Sort takes almost a quarter of the time during the second run through. The sort method is identical each time it's run.</p>
  
  <p>The class the methods are contained in is newly created each time the method is called.</p>
  
  <p>So, I'm curious as to why the first call takes almost a full second longer than the second call.</p>