MCPcopy Index your code
hub / github.com/artyushov/idea-jmh-plugin

github.com/artyushov/idea-jmh-plugin @v1.6.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.6.0 ↗ · + Follow
100 symbols 210 edges 15 files 14 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Intellij IDEA plugin for Java Microbenchmark Harness (JMH)

This is a plugin that allows you to use JMH in the same way as JUnit. Here are the features that are already implemented:

  1. @Benchmark method generation
  2. Running a separate @Benchmark method
  3. Running all the benchmarks in a class

quick demo

How do I use this?

First of all, you must have jmh-core and jmh-generator-annprocess on the classpath of your module.

After that install the plugin. You can do this directly from IDEA — search for JMH in plugin repositories.

Then you can use the plugin the same way you use JUnit. To generate a new benchmark method run Generate... action. Press Alt+Insert or in MacOS Ctrl + N. Or just right click in your editor pane and select Generate micro benchmark.

To run a separate benchmark method move the cursor to the method declaration and invoke Run action. Press Ctrl + Shift + F10. Do the same actions to run all the benchmarks in a class, just move your cursor to the class declaration.

Invoking Run actions will create a new configuration with default parameters JMH provides. If you want to change these parameters just edit this configuration. To edit default parameters for all your benchmarks, modify the "JMH" run configuration template.

Please, note that when running a benchmark Annotation processing must be enabled in your IDE.

Doesn't it affect the quality of my benchmarks?

A brief research shows that benchmark results are affected, but not that much. The whole research is described in Research results. Long story short, the maximum means difference observed was 2.2%.

Run Configuration

The following screenshot configures JMH to run the benchmark org.openjdk.bench.java.util.UUIDBench.fromString using the async-profiler from a customized java.library.path

Run Configuration

Common problems

Under Windows the following error might show up:

ERROR: org.openjdk.jmh.runner.RunnerException:
ERROR: Exception while trying to acquire the JMH lock (C:\WINDOWS\/jmh.lock):

This is caused by running JMH benchmarks with an empty environment. To fix this error, define a TMP or TEMP environment variable which points to a writable directory. Alternatively, specify the JVM argument java.io.tmpdir and set it to a writable directory, for instance -Djava.io.tmpdir=C:\temp.

Develop

To understand the plugin sources please read * Run Configurations Architectural Overview * Run Configuration Management

Related projects

Plugin on JetBrains Marketplace

Please rate the plugin on Marketplace

Core symbols most depended-on inside this repo

Shape

Method 86
Class 13
Enum 1

Languages

Java100%

Modules by API surface

src/main/java/ru/artyushov/jmhPlugin/configuration/JmhConfiguration.java37 symbols
src/main/java/ru/artyushov/jmhPlugin/action/BenchmarkMethodHandler.java11 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/ConfigurationUtils.java9 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhEntryPoint.java7 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhConfigurationProducer.java7 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhBenchmarkCommandLineState.java6 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhSettingsEditor.java5 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhConfigurable.java5 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhConfigurationType.java4 symbols
src/main/java/ru/artyushov/jmhPlugin/inspection/JmhInspections.java3 symbols
src/main/java/ru/artyushov/jmhPlugin/configuration/JmhRunLineMarkerContributor.java2 symbols
src/main/java/ru/artyushov/jmhPlugin/action/GenerateMicroBenchmarkAction.java2 symbols

For agents

$ claude mcp add idea-jmh-plugin \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page