GH-1146 - Add microbenchmarks.
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -90,6 +90,7 @@ limitations under the License.
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
@@ -133,8 +134,9 @@ limitations under the License.
|
||||
</activation>
|
||||
|
||||
<modules>
|
||||
<module>spring-modulith-integration-test</module>
|
||||
<module>spring-modulith-benchmarks</module>
|
||||
<module>spring-modulith-examples</module>
|
||||
<module>spring-modulith-integration-test</module>
|
||||
</modules>
|
||||
|
||||
</profile>
|
||||
@@ -166,6 +168,7 @@ limitations under the License.
|
||||
<id>prepare-release</id>
|
||||
|
||||
<modules>
|
||||
<module>spring-modulith-benchmarks</module>
|
||||
<module>spring-modulith-distribution</module>
|
||||
<module>spring-modulith-examples</module>
|
||||
<module>spring-modulith-integration-test</module>
|
||||
|
||||
95
spring-modulith-benchmarks/pom.xml
Normal file
95
spring-modulith-benchmarks/pom.xml
Normal file
@@ -0,0 +1,95 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.modulith</groupId>
|
||||
<artifactId>spring-modulith</artifactId>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<name>Spring Modulith - Benchmarks</name>
|
||||
<artifactId>spring-modulith-benchmarks</artifactId>
|
||||
|
||||
<properties>
|
||||
<jmh.version>1.37</jmh.version>
|
||||
<!-- Customized as the MBR is currently not compatible with JUnit 5.12 -->
|
||||
<junit-jupiter.version>5.11.4</junit-jupiter.version>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<module.name>org.springframework.modulith.benchmark</module.name>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.modulith</groupId>
|
||||
<artifactId>spring-modulith-events-core</artifactId>
|
||||
<version>1.3.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
|
||||
<artifactId>microbenchmark-runner-junit5</artifactId>
|
||||
<version>0.4.0.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.modulith.events.core;
|
||||
|
||||
import jmh.mbr.junit5.Microbenchmark;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
import org.springframework.modulith.events.core.DefaultEventPublicationRegistry.PublicationsInProgress;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Warmup(iterations = 10, time = 2)
|
||||
@Measurement(iterations = 10, time = 2)
|
||||
@Microbenchmark
|
||||
public class PublicationsInProgressBenchmarks {
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public static class Fixture implements Iterable<TargetEventPublication> {
|
||||
|
||||
private static final int NUMBER = 100;
|
||||
|
||||
private final List<Object> events = new ArrayList<>();
|
||||
private final List<PublicationTargetIdentifier> identifiers = new ArrayList<>();
|
||||
private final List<TargetEventPublication> randomPublications = new ArrayList<>();
|
||||
|
||||
PublicationsInProgress inProgress;
|
||||
|
||||
public Fixture() {
|
||||
|
||||
this.inProgress = new DefaultEventPublicationRegistry.PublicationsInProgress();
|
||||
|
||||
for (int i = 0; i < NUMBER; i++) {
|
||||
|
||||
var event = new Event(UUID.randomUUID().toString());
|
||||
|
||||
for (int j = 0; j < NUMBER; j++) {
|
||||
|
||||
var identifier = PublicationTargetIdentifier.of(UUID.randomUUID().toString());
|
||||
|
||||
events.add(event);
|
||||
identifiers.add(identifier);
|
||||
|
||||
inProgress.register(TargetEventPublication.of(event, identifier));
|
||||
}
|
||||
}
|
||||
|
||||
var random = new Random();
|
||||
|
||||
for (int i = 0; i < NUMBER; i++) {
|
||||
|
||||
var event = events.get(random.nextInt(NUMBER));
|
||||
var id = identifiers.get(random.nextInt(NUMBER));
|
||||
|
||||
randomPublications.add(TargetEventPublication.of(event, id));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<TargetEventPublication> iterator() {
|
||||
return randomPublications.iterator();
|
||||
}
|
||||
|
||||
@Value
|
||||
static class Event {
|
||||
String value;
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void inProgressPublicationsAccess(Fixture fixture, Blackhole sink) {
|
||||
|
||||
for (TargetEventPublication publication : fixture) {
|
||||
sink.consume(fixture.inProgress.getPublication(publication.getEvent(), publication.getTargetIdentifier()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user