title: Java 11 string concatenation performance Vs java 8
body: <p>Does anyone know why I get such different performance when running this code on Java 8 and Java 11? </p>
  
  <p>Without using any runtime flags, it appears that this code runs significantly slower under Java 11 compared to Java 8.</p>
  
  <pre><code>import java.util.Date;
  
  public class PerformanceExperiment {
      public static volatile String s = "";
  
      public static void main(String[] args)
      {                         
          System.out.println("Starting performance test");
          String s1 = "STRING ONE";
          String s2 = "STRING TWO";
          long now1 = (new Date()).getTime();
          for (long i = 0; i &lt; 1_000_000_00; i++)
          {
              s = "abc " + s1 + " def " + s2;
          }
          long now2 = (new Date()).getTime();
          System.out.println("initial block took " + (now2 - now1) + "ms");
          for (long i = 0; i &lt; 4_000_000_00; i++)
          {
              s = "abc " + s1 + " def " + s2;
          }
          long now3 = (new Date()).getTime();
          System.out.println("Main block took " + (now3 - now2) + "ms");
      }
  }
  </code></pre>
  
  <p>I have tried numerous command line flags but have not managed to find anything that matches the Java 8 performance.</p>
  
  <p>I have only tested this on Windows so it could behave differently on other operating systems.</p>