为什么JMH会运行不同的叉子? [英] Why does JMH run different forks?

查看:214
本文介绍了为什么JMH会运行不同的叉子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JMH基准测试框架( http://openjdk.java.net/projects/code- tools / jmh / )在我的代码上运行基准测试。我的理解是JMH在基准测试期间多次分配JVM,以便丢弃由JVM在执行期间执行的即时(JIT)分析构建的任何配置文件。

I am using the JMH benchmarking framework (http://openjdk.java.net/projects/code-tools/jmh/) to run benchmarks on my code. My understanding is that JMH forks the JVM multiple times during benchmarking in order to discard any profiles built up by the just-in-time (JIT) profiling performed by the JVM during execution.

我理解为什么这在某些情况下很有用,例如下面的内容(从 http://java-performance.info/jmh中逐字复制) / ):

I understand why this is useful in some cases such as the below (copied verbatim from http://java-performance.info/jmh/):


默认情况下,JHM为每个试验(迭代集)分配一个新的java进程。这是为了保护测试免受先前收集的配置文件 - 有关其他已加载类及其执行信息的信息。例如,如果你有两个类实现相同的接口并测试它们的性能,那么第一个实现(按测试顺序)可能比第二个(在同一个JVM中)更快,因为JIT取代在发现第二个实现之后,direct方法使用接口方法调用调用第一个实现。

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.

但是,在您进行基准测试的情况下重复使用相同的代码是否有任何优势来运行10个叉子,每个20次迭代,而不是1次叉子,200次迭代?

However, in the case where you are benchmarking the same code repeatedly is there any advantage to running say 10 forks of 20 iterations each instead of 1 fork with 200 iterations?

非常感谢,

Danny

推荐答案

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

Some people insist that another problem solved by using forks is run-to-run variance: http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_13_RunToRun.java

但是,任何认真的工程师必须能够对基准测试环境进行足够的控制,以消除运行之间的任何差异。看到人们使用叉子来克服他们的懒惰或者对他们的基准实际执行方式缺乏了解是令人沮丧的。

However, any serious engineer must be able to exercise sufficient control over the benchmarking environment to eliminate any difference between runs. It is disheartening to see people using forks to overcome their laziness or lack of understanding of how their benchmarks are actually executed.

这篇关于为什么JMH会运行不同的叉子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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