- Mastering High Performance with Kotlin
- Igor Kucherenko
- 118字
- 2021-06-25 20:55:26
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.
推薦閱讀
- 精通Nginx(第2版)
- Mastering AWS Lambda
- Python快樂編程:人工智能深度學習基礎
- Hands-On Microservices with Kotlin
- 編程與類型系統
- Web Developer's Reference Guide
- Java 9 Programming By Example
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- SEO教程:搜索引擎優化入門與進階(第3版)
- Android開發進階實戰:拓展與提升
- R語言與網站分析
- Build Your Own PaaS with Docker
- Python Natural Language Processing
- Mastering Web Application Development with Express
- Developing Multi:Platform Apps with Visual Studio Code