Java Math.pow(x,2.0)与Math.pow(x,2.0000001)的性能 [英] Java Math.pow(x,2.0) vs Math.pow(x,2.0000001) performance

查看:398
本文介绍了Java Math.pow(x,2.0)与Math.pow(x,2.0000001)的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较 pow(x,2.0) pow(x,2.0000001)的效果,我虽然 2.0 会快得多,但它们的速度相同。我甚至通过使用 -Xint 参数运行jar来删除JIT优化。

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!

推荐答案

尽管有不公平的downvotes,这个问题很有道理,因为它揭示了真实的JVM错误。

In spite of unfair downvotes, the question makes much sense, since it reveals the real JVM bug.

运行Oracle JDK时, Math.pow(x,2.0)的性能差异很大JVM版本。

When you run Oracle JDK the performance of Math.pow(x, 2.0) highly varies between JVM versions.


  • 在JDK 7u40之前 Math.pow 使用过的软件实现,即它简单地称为 __ieee754_pow 功能,模拟软件操作。它相当慢,但确实有一个y == 2的特殊情况。

  • 由于JDK 7u40 Math.pow 成为了由JIT转换为FPU指令的JVM内在函数。但是,通过此优化,特殊情况已丢失,导致y == 2的性能回归,请参阅 bug JDK-8029302

  • 此性能回归已在JDK 8u25和即将推出的7u80中得到修复。由于JDK 8u25 Math.pow 对所有值的工作速度足够快,但y == 2的速度非常快。请参阅相关问题

  • Before JDK 7u40 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.
  • Since JDK 7u40 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.
  • This performance regression has been fixed in JDK 8u25 and upcoming 7u80. Since JDK 8u25 Math.pow works fast enough for all values, but extremely fast for y == 2. See the related question.

PS 在我的机器上使用不同版本的JDK 100M调用 Math.pow 的大致时间(秒)。

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      

这篇关于Java Math.pow(x,2.0)与Math.pow(x,2.0000001)的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆