Created
July 17, 2015 15:20
-
-
Save TrevorS/cba05a0a9bb53376cb1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
public class TestSB { | |
private static String a = ""; | |
private static String b = ""; | |
private static int iterations = 100000; | |
private static long start; | |
public static void main(String[] args) { | |
start = System.nanoTime(); | |
IntStream.range(0, iterations).forEach(i -> a += i); | |
System.out.println("concat took: " + (System.nanoTime() - start) + " ms."); | |
start = System.nanoTime(); | |
StringBuilder sb = new StringBuilder(); | |
IntStream.range(0, iterations).forEach(i -> sb.append(i)); | |
String s = sb.toString(); | |
System.out.println("sb took: " + (System.nanoTime() - start) + " ms."); | |
} | |
} | |
// concat took: 8298702665 ms. | |
// sb took: 7196031 ms. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment