On 30.07.2013 20:47, Aleksey Shipilev wrote:
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));
}
}
Thanks, Aleksey!
Yes, this is much clearer. And shows much better improvement too :-)
Now it becomes ~45%.
Benchmark Mode Thr Cnt Sec
Mean Mean error Units
o.b.PowerOfTwoBench.benchPowerOfTwoA avgt 1 20 5
16.872 0.276 msec/op
o.b.PowerOfTwoBench.benchPowerOfTwoB avgt 1 20 5
9.304 0.378 msec/op
Sincerely yours,
Ivan
-Aleksey.