I think there are cases where you want to take a microbenchmark while changing the VM argument. For arguments that affect the JIT compiler, simply running the program and measuring the time I can't measure the effect well. This is because the JIT compiler runs and optimizes the code at the timing that the VM determines during program execution, so it is not possible to measure how effective the change in the VM argument was.
In such cases, it is convenient to use the benchmarking tool JMH. How to use JMH is explained in this article, so from now on, the benchmark in JMH I will explain how to specify the VM argument at the time.
You can specify the VM argument by adding the Fork annotation to the benchmarking method and using the JvmArgsAppend attribute as shown below. In this example, "-XX: -Inline" is specified.
@Benchmark
@Fork(jvmArgsAppend = "-XX:-Inline") //Specify VM argument with annotation
public String No inline expansion() {
return execute();
}
Also, by implementing as follows, it is possible to benchmark the presence or absence of VM arguments at the same time.
@Benchmark
public String Inline expansion available() {
return execute();
}
@Benchmark
@Fork(jvmArgsAppend = "-XX:-Inline") //Specify VM argument with annotation
public String No inline expansion() {
return execute();
}
Recommended Posts