On 07/30/2013 07:35 PM, Ivan Gerasimov wrote:
> I also created a benchmark test to make sure the improvement is observable.
> Here's the jmh benchmark I used:
> http://cr.openjdk.java.net/~igerasim/bench/powoftwo/src/main/java/org/benches/PowerOfTwoBench.java
> <http://cr.openjdk.java.net/%7Eigerasim/bench/powoftwo/src/main/java/org/benches/PowerOfTwoBench.java>

The nit: volatile writes are probably offset the results too much, it's
better to use the explicit idiom to feed the values:

    @GenerateMicroBenchmark
    public void benchPowerOfTwoA(BlackHole bh) {
        for (i = 0; i != MAX_I; ++i) {
            bh.consume(roundUpToPowerOf2A(i));
        }
    }

-Aleksey.

Reply via email to