Skip to content

Commit

Permalink
ICU-23061: Performance test for Lowercase transliterator; introduce JMH
Browse files Browse the repository at this point in the history
JMH is the OpenJDK microbenchmark harness. It is a standardized tool with
many integrations and provides a lot of out-of-the-box functionality.

No existing perf-tests are changed

https://github.com/openjdk/jmh
  • Loading branch information
stevenschlansker committed Feb 25, 2025
1 parent a35ccc6 commit f332c3c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
3 changes: 3 additions & 0 deletions icu4j/perf-tests/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ COLLATION TESTS
The collation tests run only on the command line with tabular output:
perl collationperf.pl |& tee collation_output.txt

JMH
Some performance tests run using OpenJDK JMH. These may be launched with:
java -jar perf-tests/target/jmh-benchmarks.jar

OTHER COMMAND LINE TESTS
Additional tests are run from the command line, each producing an HTML
Expand Down
57 changes: 56 additions & 1 deletion icu4j/perf-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<module-name>perf_tests</module-name>
<jmh.version>1.37</jmh.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -43,12 +44,23 @@
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<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>
</dependencies>

<build>
<plugins>
<plugin>
<!-- Copy dependencies by default, so that everythign is easier to run
<!-- Copy dependencies by default, so that everything is easier to run
without having to explicitly list all kind of folders in classpath.
Just use `./target/*` and `./target/dependency/*`
-->
Expand All @@ -63,6 +75,49 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessors>
<annotationProcessor>org.openjdk.jmh.generators.BenchmarkProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>jmh-benchmarks</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</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>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ibm.icu.dev.test.perf;

import java.util.concurrent.TimeUnit;

import com.ibm.icu.text.Transliterator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;

@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class LowercaseTransliteratorPerf {

static final Transliterator LOWER = Transliterator.getInstance("Lower");

@Benchmark
public String testShort() {
return LOWER.transliterate("Cat");
}

@Benchmark
public String testSentence() {
return LOWER.transliterate("The Quick Brown Fox Jumped Over The Lazy Dog");
}

}

0 comments on commit f332c3c

Please sign in to comment.