Created
January 28, 2026 20:58
-
-
Save JohnTortugo/5cdcd8b586e09e759b0402d720e97a66 to your computer and use it in GitHub Desktop.
Create JMH Project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create project | |
| mvn archetype:generate \ | |
| -DarchetypeGroupId=org.openjdk.jmh \ | |
| -DarchetypeArtifactId=jmh-java-benchmark-archetype \ | |
| -DarchetypeVersion=1.37 \ | |
| -DgroupId=com.jtortugo \ | |
| -DartifactId=TortugoBenchmark \ | |
| -Dversion=HEAD \ | |
| -DinteractiveMode=false | |
| # Add this to the plugin section of the pom.xml | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-compiler-plugin</artifactId> | |
| <version>3.11.0</version> | |
| <configuration> | |
| <release>21</release> | |
| <annotationProcessorPaths> | |
| <path> | |
| <groupId>org.openjdk.jmh</groupId> | |
| <artifactId>jmh-generator-annprocess</artifactId> | |
| <version>${jmh.version}</version> | |
| </path> | |
| </annotationProcessorPaths> | |
| </configuration> | |
| </plugin> | |
| # Create benchmark | |
| package com.jtortugo; | |
| import org.openjdk.jmh.annotations.*; | |
| import org.openjdk.jmh.infra.*; | |
| import org.openjdk.jmh.runner.*; | |
| import org.openjdk.jmh.runner.options.*; | |
| import java.io.*; | |
| import java.nio.charset.StandardCharsets; | |
| import java.util.concurrent.TimeUnit; | |
| import java.util.zip.*; | |
| @State(Scope.Thread) | |
| @BenchmarkMode(Mode.Throughput) | |
| @OutputTimeUnit(TimeUnit.MICROSECONDS) | |
| @Warmup(iterations = 5, time = 1) | |
| @Measurement(iterations = 10, time = 1) | |
| @Fork(3) | |
| public class TortugoBenchmark { | |
| @Param({"1", "2", "3"}) | |
| int param; | |
| @Setup(Level.Trial) | |
| public void setup() throws IOException { | |
| ... | |
| } | |
| @Benchmark | |
| public void bench(Blackhole bh) throws IOException { | |
| ... | |
| } | |
| public static void main(String[] args) throws RunnerException { | |
| Options opt = new OptionsBuilder() | |
| .include(TortugoBenchmark.class.getSimpleName()) | |
| .build(); | |
| new Runner(opt).run(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment