All pastes #901604 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-12 20:14 UTC
rendered paste body
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.");
	}

}