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

我使用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

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

相关文章

应用场景 C端用户提交工单、工单创建完成之后、会发布一条工...
线程类,设置有一个公共资源 package cn.org.chris.concurre...
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量