加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 为什么JMH运行不同的fork?

发布时间:2020-12-14 16:37:25 所属栏目:Java 来源:网络整理
导读:我使用JMH基准框架( http://openjdk.java.net/projects/code-tools/jmh/)在我的代码上运行基准.我的理解是,JMH在分析过程中多次分配JVM,以便丢弃在执行期间由JVM执行的即时(JIT)分析构建的任何配置文件. 我明白为什么这在某些情况下是有用的,如下列(从http:/
我使用JMH基准框架( http://openjdk.java.net/projects/code-tools/jmh/)在我的代码上运行基准.我的理解是,JMH在分析过程中多次分配JVM,以便丢弃在执行期间由JVM执行的即时(JIT)分析构建的任何配置文件.

我明白为什么这在某些情况下是有用的,如下列(从http://java-performance.info/jmh/逐字复制):

By default JHM forks a new java process for each trial (set of iterations). This is required to defend the test from previously collected “profiles” – information about other loaded classes and their execution information. For example,if you have 2 classes implementing the same interface and test the performance of both of them,then the first implementation (in order of testing) is likely to be faster than the second one (in the same JVM),because JIT replaces direct method calls to the first implementation with interface method calls after discovering the second implementation.

但是,如果您重复对相同代码进行基准测试,那么运行20次迭代的10个叉,而不是1次与200次迭代有任何优势?

非常感谢,

丹尼

解决方法

有些人坚持使用叉子解决的另一个问题是运行方差: http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_13_RunToRun.java

然而,任何严肃的工程师都必须能够对基准环境进行充分的控制,以消除运行之间的任何差异.看到人们用叉子来克服懒惰或对基准实际执行情况缺乏了解是令人沮丧的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读