I am trying to compare performance of
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.powused 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.powbecame 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.powworks 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