我明白为什么这在某些情况下是有用的,如下列(从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次迭代有任何优势?
非常感谢,
丹尼
解决方法
然而,任何严肃的工程师都必须能够对基准环境进行充分的控制,以消除运行之间的任何差异.看到人们用叉子来克服懒惰或对基准实际执行情况缺乏了解是令人沮丧的.