public class StringPerfTest {
public static void main(String[] args) throws InterruptedException {
long startTime = System.nanoTime();
int count = 10000;
String s = new String();
for (int i = 0; i < count; i++) {
s = s + 'a';
}
System.out.println("Done in " + (System.nanoTime() - startTime)
/ 1000000 + " ms.");
System.gc();
Thread.sleep(1000);
startTime = System.nanoTime();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
sb.append('a');
}
System.out.println("Done in " + (System.nanoTime() - startTime)
/ 1000000 + " ms.");
}
}