All pastes #901612 Raw Edit

Unnamed

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