@@ -0,0 +1,1710 @@
+%0Apublic class MicrobenchmarkStringBuilder %7B%0A%0A%09// this is %0A%09public static String concatTest(String%5B%5D arr) %7B%0A%09%09String concatted = %22%22;%0A%09%09for (String s : arr) %7B%0A%09%09%09concatted += s;%0A%09%09%7D%0A%09%09return concatted;%0A%09%7D%0A%0A%09// this is linear%0A%09public static String builderTest(String%5B%5D arr) %7B%0A%09%09StringBuilder builder = new StringBuilder();%0A%09%09for (String s : arr) %7B%0A%09%09%09builder.append(s);%0A%09%09%7D%0A%09%09return builder.toString();%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%0A%09%09String%5B%5D arr = new String%5B500%5D;%0A%09%09for (int i = 0; i %3C arr.length; i++) %7B%0A%09%09%09arr%5Bi%5D = Double.toString(Math.random());%0A%09%09%7D%0A%0A%09%09System.out.println(%22String 0 = %22 + arr%5B0%5D);%0A%0A%09%09// warm up test 1.%0A%09%09System.out.println(%22Warming up code...%22);%0A%09%09String reString = null;%0A%09%09for (int i = 0; i %3C 5000; i++) %7B%0A%09%09%09reString = concatTest(arr);%0A%09%09%7D%0A%09%09System.out.println(reString.substring(0, 20));%0A%0A%09%09// do test 1%0A%09%09System.out.println(%22Running benchmark 1.%22);%0A%09%09long start = System.currentTimeMillis();%0A%09%09for (int i = 0; i %3C 5000; i++) %7B%0A%09%09%09reString = concatTest(arr);%0A%09%09%7D%0A%09%09long end = System.currentTimeMillis();%0A%09%09System.out.println(reString.substring(0, 20));%0A%09%09System.out.println(%22Simple concat timing: %22 + (end - start));%0A%0A%09%09// warm up test 2%0A%09%09System.out.println(%22Warming up code 2...%22);%0A%09%09String reString2 = null;%0A%09%09for (int i = 0; i %3C 5000; i++) %7B%0A%09%09%09reString2 = builderTest(arr);%0A%09%09%7D%0A%09%09System.out.println(reString2.substring(0, 20));%0A%0A%09%09// do test 1%0A%09%09System.out.println(%22Running benchmark 2.%22);%0A%09%09long start2 = System.currentTimeMillis();%0A%09%09for (int i = 0; i %3C 5000; i++) %7B%0A%09%09%09reString2 = builderTest(arr);%0A%09%09%7D%0A%09%09long end2 = System.currentTimeMillis();%0A%09%09System.out.println(reString2.substring(0, 20));%0A%09%09System.out.println(%22builder timing: %22 + (end2 - start2));%0A%0A%09%7D%0A%0A%7D%0A

Create MicrobenchmarkStringBuilder.java