Skip to content

Commit

Permalink
Introduce JMH profile and src/jmh/java configuration to co-locate J…
Browse files Browse the repository at this point in the history
…MH benchmarks.

Closes #2407
  • Loading branch information
mp911de committed Oct 29, 2024
1 parent ed28cfa commit 1f8a521
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 4 deletions.
35 changes: 33 additions & 2 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,37 @@ Upgrading to 2.7 is *not allowed*.
** During the milestone phase of a new release train, upgrade to the latest version of a dependency unless compatibility with a former version is required.
Upgrades to new major versions are allowed, too, but consider ways to support multiple major versions for one release train to allow a smoother transition.

[[advanced.benchmarks]]
=== Benchmarks

We use JMH for micro-benchmarks.

Our benchmarks are located in the `src/jmh/java` directory so that we compile these as part of our main build. To run benchmarks during development we leverage JUnit 5 and the https://github.com/mp911de/microbenchmark-runner[Microbenchmark Runner].
Enable the `jmh` Maven Profile, add `@Testable` to the benchmark you want to run (of the benchmark class) and run it as it was a JUnit test right from your IDE.

NOTE: Microbenchmark Runner is not a tool for running final benchmarks, rather it helps to quickly run benchmarks during development to reduce turnaround time.

Benchmarks aren't ran during the build.

JMH's Benchmark Generator (Annotation Processor) must be enabled in each module with the Maven Compiler, see the following example:

[source,xml]
----
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
----

[[advanced.change-tracking]]
=== Change tracking

Expand Down Expand Up @@ -192,7 +223,7 @@ Make sure you keep the original author when amending.
curl $PULL_REQUEST_URL.patch | git am --ignore-whitespace
----

* If the you merge back a feature branch and multiple developers contributed to that, try to rearrange to commits and squash the into a single commit per developer.
* If you merge back a feature branch and multiple developers contributed to that, try to rearrange to commits and squash the into a single commit per developer.
Combine the commit messages and edit them to make sense.
* Before pushing the changes to the remote repository, amend the commit(s) to be pushed and add a reference to the pull request to them.
This will cause the pull request UI in GitHub show and link those commits.
Expand All @@ -201,5 +232,5 @@ This will cause the pull request UI in GitHub show and link those commits.
----
Original pull request #??
Original pull request: #??
----
58 changes: 58 additions & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<jacoco>0.8.12</jacoco>
<jmolecules>1.9.0</jmolecules>
<jmolecules-integration>0.21.0</jmolecules-integration>
<jmh>1.37</jmh>
<jsonpath>2.6.0</jsonpath>
<!-- Deprecated: Use junit-vintage-engine and JUnit 4 is included as transitive dependency -->
<junit>4.13.2</junit>
Expand Down Expand Up @@ -936,6 +937,24 @@
</repositories>
</profile>

<profile>
<id>jmh</id>
<dependencies>
<dependency>
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
<artifactId>microbenchmark-runner-junit5</artifactId>
<version>0.4.0.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</profile>

</profiles>

<dependencyManagement>
Expand Down Expand Up @@ -1025,6 +1044,12 @@
<version>${webbeans}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<scope>test</scope>
<version>${jmh}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -1043,6 +1068,14 @@
<scope>test</scope>
</dependency>

<!-- JMH -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<scope>test</scope>
<version>${jmh}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -1287,6 +1320,19 @@
</sourceDirs>
</configuration>
</execution>
<execution>
<id>jmh-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/jmh/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/jmh/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>

Expand Down Expand Up @@ -1377,6 +1423,18 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-jmh-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/jmh/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-kotlin-source</id>
<phase>prepare-package</phase>
Expand Down
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@
</executions>
</plugin>

<!-- Make sure we build on Java 8 with only release dependencies -->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down

0 comments on commit 1f8a521

Please sign in to comment.