Q:
While the command line approach is the suggested one, some people prefer to use IDEs. The user experience varies between different IDEs, but we will outline the general things here. Running benchmarks from the IDE is generally not recommended due to generally uncontrolled environment in which the benchmarks run.
- Setting up the benchmarking project. Some IDEs provide the GUI to create the Maven project from the given archetype. Make sure your IDE knows about Central archetype catalog, and look for org.openjdk.jmh:jmh-${lang}-benchmark-archetype there. Alternatively, you can use the command line to generate the benchmark project, see above.
NOTE: JMH is not intended to be used in the same way as a typical testing library such as JUnit. Simply adding the jmh-core
jar file to your build is not enough to be able to run benchmarks.
- Building the benchmarks.
Most IDEs are able to open/import Maven projects, and infer the build configuration from Maven project configuration. IDEA and Netbeans are able to build JMH benchmark projects with little to no effort. Eclipse build configuration may need to set up JMH annotation processors to run.
- Running the benchmarks. There is no direct support for JMH benchmarks in the IDE, but one can use JMH Java API to invoke the benchmark. It usually amounts to having the
main
method, which will then call into JMH. See JMH Samples for the examples of this approach. Before you run any benchmark, the project build is required. Most IDEs do this automatically, but some do require explicit build action to be added before the run: adding Maven target "install
" should help there.