June 2018
Intermediate to advanced
316 pages
6h 34m
English
If we want to get the result in a more readable format, we can specify a time unit. In our case, it would be better to use NANOSECONDS. To do so, we can rewrite our method as follows:
@Benchmark@BenchmarkMode(Mode.AverageTime)@OutputTimeUnit(TimeUnit.NANOSECONDS)public void testMethod() { int a = 3; int b = 4; int c = a + b;}
The output will now be:
# Run progress: 0.00% complete, ETA 00:00:10 # Fork: 1 of 1 # Warmup Iteration 1: 0.345 ns/op # Warmup Iteration 2: 0.342 ns/op # Warmup Iteration 3: 0.342 ns/op # Warmup Iteration 4: 0.337 ns/op # Warmup Iteration 5: 0.342 ns/op Iteration 1: 0.336 ns/op Iteration 2: 0.333 ns/op Iteration 3: 0.342 ns/op Iteration 4: 0.340 ns/op Iteration 5: 0.340 ns/op Result "org.sample.MyBenchmark.testMethod": ...
Read now
Unlock full access