/*
 * Written by Doug Lea with assistance from members of JCP JSR-166
 * Expert Group and released to the public domain, as explained at
 * http://creativecommons.org/licenses/publicdomain
 */

import java.util.concurrent.atomic.*;

public class LazySetTest {
    static final int N = 1 << 24;

    final AtomicInteger ai = new AtomicInteger();
    final AtomicLong al = new AtomicLong();
    final AtomicReference<Integer> ar = new AtomicReference<Integer>();

    void test() {
        long now;
        long last = System.nanoTime();
        for (int k = 0; k < 5; ++k) {
            System.out.print("int set      ");
            for (int i = 0; i < N; ++i)
                ai.set(i);
            now = System.nanoTime();
            System.out.println((double)(now - last) / N);
            last = now;
            System.out.print("int lazySet  ");
            for (int i = 0; i < N; ++i)
                ai.lazySet(i);
            now = System.nanoTime();
            System.out.println((double)(now - last) / N);
            last = now;

            System.out.print("long set     ");
            for (int i = 0; i < N; ++i)
                al.set(i);
            now = System.nanoTime();
            System.out.println((double)(now - last) / N);
            last = now;
            System.out.print("long lazySet ");
            for (int i = 0; i < N; ++i)
                al.lazySet(i);
            now = System.nanoTime();
            System.out.println((double)(now - last) / N);
            last = now;

            System.out.print("ref set      ");
            for (int i = 0; i < N; ++i)
                ar.set(i);
            now = System.nanoTime();
            System.out.println((double)(now - last) / N);
            last = now;
            System.out.print("ref lazySet  ");
            for (int i = 0; i < N; ++i)
                ar.lazySet(i);
            now = System.nanoTime();
            System.out.println((double)(now - last) / N);
            last = now;

        }
    }


    public static void main(String[] args) {
        LazySetTest t = new LazySetTest();
        t.test();
    }
}

    
