I am trying to compare performance of pow(x,2.0)
and pow(x,2.0000001)
and I though that 2.0
would be much faster, but they are at the same speed. I even removed JIT optimizations by running jar with -Xint
parameter.
Any idea why is that, please? Thanks a lot!
In spite of unfair downvotes, the question makes much sense, since it reveals the real JVM bug.
When you run Oracle JDK the performance of Math.pow(x, 2.0)
highly varies between JVM versions.
Math.pow
used software implementation, i.e. it simply called __ieee754_pow function that emulates the operation in software. It was rather slow, but it did have a special case for y == 2.Math.pow
became a JVM intrinsic that was translated into FPU instructions by the JIT. However, with this optimization the special case has been lost, resulting in a performance regression for y == 2, see bug JDK-8029302.Math.pow
works fast enough for all values, but extremely fast for y == 2. See the related question.P.S. The approximate times in seconds for 100M invocations of Math.pow
on my machine with different versions of JDK.
Math.pow(x, 2.0) Math.pow(x, 2.0000001)
JDK 7u25 3.0 30.4
JDK 7u40 11.1 11.1
JDK 8u40 0.1 11.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With