// 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 GC {
    private static final int N = 1000000000; 
    private static long loop;
    private static void dummy1() {
    }
    private static void dummy2(byte[] b) {
    }
    public static void setup()
    {
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < N; i++) {
            dummy1();
        }
        long t2 = System.currentTimeMillis();
        loop = t2 - t1;
    }
    public static void test(int n)
    {
        int allocs = N/n;
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < allocs; i++) {
            byte[] b = new byte[n];
            dummy2(b);
        }
        long t2 = System.currentTimeMillis();
        System.out.printf("size %7d : %.6f ms/alloc\n", n, (t2 - t1 - loop/(double)n)/allocs);
    }
    public static void main(String[] args) {
        setup();
        test(1);
        test(10);
        test(100);
        test(1000);
        test(10000);
        test(100000);
        test(1000000);
    }
}
