// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class StringAlloc {
    private static final int N = 1000000;
    public static void test(int n) {
        StringBuffer sb = new StringBuffer();
        for(int j = 0; j < n; j++) {
            sb.append('A');
        }
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < N; i++) {
            String s2 = sb.toString();
        }
        long t2 = System.currentTimeMillis();
        System.out.println(n + " : " + (int)(N/((t2 - t1)/1000.0)));
    }
    public static void main(String[] args) {
        test(1);
        test(10);
        test(100);
        test(1000);
        test(10000);
        test(100000);
        test(1000000);
        test(10000000);
        test(100000000);
    }
}
