Skip to content

Commit

Permalink
Merge pull request #3 from ponder-lab/benchmark
Browse files Browse the repository at this point in the history
Add JMH annotation
  • Loading branch information
bgprudhomme authored Feb 21, 2024
2 parents ab6f897 + f8eef3b commit 095468f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ atlassian-ide-plugin.xml
sonar-project.properties
test-output/
*.pyc
jmh-results.*
dependency-reduced-pom.xml
97 changes: 97 additions & 0 deletions modules/swagger-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,91 @@
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>run-benchmarks</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>org.openjdk.jmh.Main</argument>
<argument>.*</argument>
<!-- Measurement mode. -->
<argument>-bm</argument>
<argument>avgt,thrpt</argument>
<!-- Forks. -->
<argument>-f</argument>
<argument>1</argument>
<!-- Units. -->
<argument>-tu</argument>
<argument>ms</argument>
<!-- Machine-readible output. -->
<argument>-rff</argument>
<argument>jmh-results.csv</argument>
<!-- Human-readable output. -->
<argument>-o</argument>
<argument>jmh-results.txt</argument>
<!-- Fail on error. -->
<argument>-foe</argument>
<argument>true</argument>
<!-- Iterations. -->
<!-- <argument>-i</argument> -->
<!-- <argument>1</argument> -->
<!-- Warmup. -->
<argument>-wi</argument>
<argument>1</argument>
<!-- Warmup mode. -->
<!-- <argument>-wm</argument> -->
<!-- <argument>BULK</argument> -->
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
Expand Down Expand Up @@ -52,6 +137,17 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down Expand Up @@ -160,5 +256,6 @@
<coverage.complexity.minimum>0.60</coverage.complexity.minimum>
<coverage.line.minimum>0.0</coverage.line.minimum>
<coverage.missed.classes>3</coverage.missed.classes>
<jmh.version>1.37</jmh.version>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.swagger.v3.oas.models.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.Test;
import org.openjdk.jmh.annotations.*;

import java.io.IOException;
import java.util.HashSet;
Expand All @@ -41,6 +42,7 @@
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

@State(Scope.Benchmark)
public class SpecFilterTest {

private static final String RESOURCE_RECURSIVE_MODELS = "specFiles/recursivemodels.json";
Expand Down Expand Up @@ -171,11 +173,21 @@ private void validateParameters(Operation operation) {
}
}

private OpenAPI openAPI;

@Setup(Level.Trial)
public void setUp() throws IOException {
// RK: Move I/O outside the benchmark to reduce variability.
openAPI = getOpenAPI(RESOURCE_PATH);
}

// @Param({"10", "100", "1000"})
@Param({"10"})
private int numThreads;

@Test(description = "it should clone everything concurrently")
@Benchmark
public void cloneEverythingConcurrent() throws IOException {
int numThreads = 10;
final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);

ThreadGroup tg = new ThreadGroup("SpecFilterTest" + "|" + System.currentTimeMillis());
final Map<String, OpenAPI> filteredMap = new ConcurrentHashMap<>();
for (int i = 0; i < numThreads; i++) {
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,5 +664,7 @@
<transformer-maven-plugin-version>0.5.0</transformer-maven-plugin-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</sonatypeOssDistMgmtSnapshotsUrl>
<!-- RK: For some reason, javadoc creation isn't working. Let's skip it. -->
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>
</project>

0 comments on commit 095468f

Please sign in to comment.