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

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.

主站蜘蛛池模板: 临邑县| 营口市| 彩票| 贵州省| 固镇县| 林周县| 新乐市| 桦甸市| 花垣县| 淮阳县| 九龙城区| 石门县| 彭阳县| 四子王旗| 隆昌县| 宣城市| 邮箱| 蓬莱市| 咸丰县| 甘谷县| 卓尼县| 麻阳| 常宁市| 个旧市| 山西省| 礼泉县| 自贡市| 广汉市| 清远市| 高碑店市| 拉萨市| 兴宁市| 乳山市| 万荣县| 临潭县| 明溪县| 志丹县| 通江县| 桐庐县| 庆云县| 左贡县|