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