title: Java method call performance
body: <p>I have this piece of code doing <a href="https://en.wikipedia.org/wiki/Range_minimum_query" rel="noreferrer">Range Minimum Query</a>. When t = 100000, i and j are always changed in each input line, its execution time in Java 8u60 is about 12 secs.</p>
  
  <pre><code>for (int a0 = 0; a0 &lt; t; a0++) {
      String line = reader.readLine();
      String[] ls = line.split(" ");
      int i = Integer.parseInt(ls[0]);
      int j = Integer.parseInt(ls[1]);
      int min = width[i];
      for (int k = i + 1; k &lt;= j; k++) {
          if (min &gt; width[k]) {
              min = width[k];
          }
      }
      writer.write(min + "");
      writer.newLine();
  }
  </code></pre>
  
  <p>When I extract a new method to find minimum Value, the execution time is 4 times faster (about 2.5 secs).</p>
  
  <pre><code>    for (int a0 = 0; a0 &lt; t; a0++) {
          String line = reader.readLine();
          String[] ls = line.split(" ");
          int i = Integer.parseInt(ls[0]);
          int j = Integer.parseInt(ls[1]);
          int min = getMin(i, j);
          writer.write(min + "");
          writer.newLine();
      }
  
  private int getMin(int i, int j) {
      int min = width[i];
      for (int k = i + 1; k &lt;= j; k++) {
          if (min &gt; width[k]) {
              min = width[k];
          }
      }
      return min;
  }
  </code></pre>
  
  <p>I always thought that method calls are slow. But this example shows the opposite. Java 6 also demonstrates this, but the execution times is much slower in both case (17 secs and 10 secs). Can someone provide some insight into this?</p>