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

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.

主站蜘蛛池模板: 二连浩特市| 永修县| 慈利县| 宜君县| 威信县| 汤阴县| 棋牌| 靖安县| 石林| 赫章县| 商都县| 离岛区| 微山县| 边坝县| 曲沃县| 武隆县| 叶城县| 长海县| 邹平县| 康乐县| 侯马市| 沂源县| 抚顺市| 嫩江县| 镇远县| 开阳县| 台安县| 繁峙县| 颍上县| 松滋市| 托克逊县| 九江市| 清水县| 桦川县| 临西县| 海门市| 长宁区| 博白县| 习水县| 许昌县| 东丽区|