How to micro-benchmark while changing VM arguments

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.

Use of JMH

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.

How to specify VM arguments

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

How to micro-benchmark while changing VM arguments
Summary of how to write annotation arguments
How to deploy
Summary of how to implement default arguments in Java
8 Corresponds to multiple arguments
How to develop OpenSPIFe
How to use Map
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to adapt Bootstrap
How to use Twitter4J
How to install Docker
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to write dockerfile
How to uninstall Rails
How to install docker-machine
How to make shaded-jar
How to write docker-compose
How to use identity
How to use hashes
How to write Mockito
How to create docker-compose
How to use JUnit 5
How to install MySQL
How to write migrationfile
How to build android-midi-lib
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to install ngrok
How to type backslash \
How to concatenate strings
How to deal with the error ERROR: While executing gem ... (Gem :: FilePermissionError)