June 2018
Intermediate to advanced
316 pages
6h 34m
English
You can use an instance of Blackhole explicitly, but it's really useful if you're going to consume several values with the black hole. In another case, this approach just affects readability and it would be better to just return the value. The next example demonstrates correct and incorrect cases:
@BenchmarkMode(Mode.AverageTime)@OutputTimeUnit(TimeUnit.NANOSECONDS)@State(Scope.Thread)public class MyBenchmark { double x1 = Math.PI; double x2 = Math.PI * 2; @Benchmark public double baseline() { return Math.log(x1); } @Benchmark public double measureWrong() { Math.log(x1); return Math.log(x2); } @Benchmark public double measureRight_1() { return Math.log(x1) + Math.log(x2); } @Benchmark public void measureRight_2(Blackhole ...
Read now
Unlock full access