- 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.
推薦閱讀
- R語言經典實例(原書第2版)
- Redis Applied Design Patterns
- Python數據分析基礎
- Learning C++ Functional Programming
- JMeter 性能測試實戰(第2版)
- Windows Server 2012 Unified Remote Access Planning and Deployment
- 編譯系統透視:圖解編譯原理
- Learning Data Mining with R
- .NET 3.5編程
- Visual C++開發入行真功夫
- Learning Concurrent Programming in Scala
- UI設計全書(全彩)
- Fast Data Processing with Spark(Second Edition)
- Python Interviews
- Unity 5.X從入門到精通