Skip to content

Commit 3b0faed

Browse files
committed
Introduce JMH profile and src/jmh/java configuration to co-locate JMH benchmarks.
Closes #2407
1 parent e8e37b5 commit 3b0faed

File tree

3 files changed

+91
-4
lines changed

3 files changed

+91
-4
lines changed

CONTRIBUTING.adoc

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,37 @@ Upgrading to 2.7 is *not allowed*.
138138
** 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.
139139
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.
140140

141+
[[advanced.benchmarks]]
142+
=== Benchmarks
143+
144+
We use JMH for micro-benchmarks.
145+
146+
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].
147+
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.
148+
149+
NOTE: Microbenchmark Runner is not a tool for running final benchmarks, rather it helps to quickly run benchmarks during development to reduce turnaround time.
150+
151+
Benchmarks aren't ran during the build.
152+
153+
JMH's Benchmark Generator (Annotation Processor) must be enabled in each module with the Maven Compiler, see the following example:
154+
155+
[source,xml]
156+
----
157+
<plugin>
158+
<groupId>org.apache.maven.plugins</groupId>
159+
<artifactId>maven-compiler-plugin</artifactId>
160+
<configuration>
161+
<annotationProcessorPaths>
162+
<path>
163+
<groupId>org.openjdk.jmh</groupId>
164+
<artifactId>jmh-generator-annprocess</artifactId>
165+
<version>${jmh}</version>
166+
</path>
167+
</annotationProcessorPaths>
168+
</configuration>
169+
</plugin>
170+
----
171+
141172
[[advanced.change-tracking]]
142173
=== Change tracking
143174

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

195-
* 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.
226+
* 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.
196227
Combine the commit messages and edit them to make sense.
197228
* 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.
198229
This will cause the pull request UI in GitHub show and link those commits.
@@ -201,5 +232,5 @@ This will cause the pull request UI in GitHub show and link those commits.
201232
----
202233
203234
204-
Original pull request #??
235+
Original pull request: #??
205236
----

parent/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<jacoco>0.8.12</jacoco>
113113
<jmolecules>1.9.0</jmolecules>
114114
<jmolecules-integration>0.21.0</jmolecules-integration>
115+
<jmh>1.37</jmh>
115116
<jsonpath>2.6.0</jsonpath>
116117
<!-- Deprecated: Use junit-vintage-engine and JUnit 4 is included as transitive dependency -->
117118
<junit>4.13.2</junit>
@@ -936,6 +937,24 @@
936937
</repositories>
937938
</profile>
938939

940+
<profile>
941+
<id>jmh</id>
942+
<dependencies>
943+
<dependency>
944+
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
945+
<artifactId>microbenchmark-runner-junit5</artifactId>
946+
<version>0.4.0.RELEASE</version>
947+
<scope>test</scope>
948+
</dependency>
949+
</dependencies>
950+
<repositories>
951+
<repository>
952+
<id>jitpack.io</id>
953+
<url>https://jitpack.io</url>
954+
</repository>
955+
</repositories>
956+
</profile>
957+
939958
</profiles>
940959

941960
<dependencyManagement>
@@ -1025,6 +1044,12 @@
10251044
<version>${webbeans}</version>
10261045
<scope>test</scope>
10271046
</dependency>
1047+
<dependency>
1048+
<groupId>org.openjdk.jmh</groupId>
1049+
<artifactId>jmh-generator-annprocess</artifactId>
1050+
<scope>test</scope>
1051+
<version>${jmh}</version>
1052+
</dependency>
10281053
</dependencies>
10291054
</dependencyManagement>
10301055

@@ -1043,6 +1068,14 @@
10431068
<scope>test</scope>
10441069
</dependency>
10451070

1071+
<!-- JMH -->
1072+
<dependency>
1073+
<groupId>org.openjdk.jmh</groupId>
1074+
<artifactId>jmh-core</artifactId>
1075+
<scope>test</scope>
1076+
<version>${jmh}</version>
1077+
</dependency>
1078+
10461079
<dependency>
10471080
<groupId>org.mockito</groupId>
10481081
<artifactId>mockito-core</artifactId>
@@ -1287,6 +1320,19 @@
12871320
</sourceDirs>
12881321
</configuration>
12891322
</execution>
1323+
<execution>
1324+
<id>jmh-compile</id>
1325+
<phase>test-compile</phase>
1326+
<goals>
1327+
<goal>test-compile</goal>
1328+
</goals>
1329+
<configuration>
1330+
<sourceDirs>
1331+
<sourceDir>${project.basedir}/src/jmh/kotlin</sourceDir>
1332+
<sourceDir>${project.basedir}/src/jmh/java</sourceDir>
1333+
</sourceDirs>
1334+
</configuration>
1335+
</execution>
12901336
</executions>
12911337
</plugin>
12921338

@@ -1377,6 +1423,18 @@
13771423
<groupId>org.codehaus.mojo</groupId>
13781424
<artifactId>build-helper-maven-plugin</artifactId>
13791425
<executions>
1426+
<execution>
1427+
<id>add-jmh-source</id>
1428+
<phase>generate-test-sources</phase>
1429+
<goals>
1430+
<goal>add-test-source</goal>
1431+
</goals>
1432+
<configuration>
1433+
<sources>
1434+
<source>${project.basedir}/src/jmh/java</source>
1435+
</sources>
1436+
</configuration>
1437+
</execution>
13801438
<execution>
13811439
<id>add-kotlin-source</id>
13821440
<phase>prepare-package</phase>

pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@
100100
</executions>
101101
</plugin>
102102

103-
<!-- Make sure we build on Java 8 with only release dependencies -->
104-
105103
<plugin>
106104
<groupId>org.apache.maven.plugins</groupId>
107105
<artifactId>maven-enforcer-plugin</artifactId>

0 commit comments

Comments
 (0)