官术网_书友最值得收藏!

Dead Code Elimination

Another downfall of benchmarks is Dead Code Elimination (DCE). The JVM reduces computations that are redundant or eliminates them completely. Let's come back to our first implementation of the testMethod() method:

@Benchmark
public void testMethod() {
int a = 3;
int b = 4;
int c = a + b;
}

In this example, the last line will be eliminated, but it's a significant part of our benchmark. The JMH provides the essential infrastructure to fight this issue. We can just return the result of computation as follows:

@Benchmark
public int testMethod() {
int a = 3;
int b = 4;
return a + b;
}

The returned result is implicitly consumed by black holes.

主站蜘蛛池模板: 松溪县| 拜城县| 绥阳县| 华蓥市| 南澳县| 疏勒县| 苍南县| 桂平市| 浮山县| 兴义市| 常山县| 石泉县| 青神县| 仪征市| 晋州市| 汾阳市| 呼图壁县| 宁陕县| 乐平市| 汕头市| 肇庆市| 崇仁县| 南溪县| 集安市| 左云县| 莱芜市| 胶州市| 廊坊市| 安仁县| 丹东市| 安新县| 博客| 潼南县| 青海省| 甘洛县| 界首市| 昌乐县| 翁源县| 靖江市| 察哈| 师宗县|