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

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.

主站蜘蛛池模板: 灵石县| 康乐县| 离岛区| 垣曲县| 昆山市| 磐石市| 深州市| 汶川县| 开远市| 凤阳县| 瓦房店市| 平顶山市| 宿迁市| 崇左市| 静宁县| 彩票| 商城县| 日土县| 威海市| 手游| 涡阳县| 墨玉县| 宜宾市| 通州市| 旺苍县| 家居| 丰县| 甘泉县| 石家庄市| 武胜县| 青铜峡市| 彭阳县| 马鞍山市| 洛隆县| 盖州市| 普安县| 孟州市| 灯塔市| 台北市| 江山市| 牡丹江市|