From 94ec9ffea8715613ef706f89d52fb69f63902e56 Mon Sep 17 00:00:00 2001 From: Steven Schlansker Date: Tue, 25 Feb 2025 10:25:04 -0800 Subject: [PATCH] ICU-23061 Performance test for Lowercase transliterator; introduce JMH 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 --- icu4j/perf-tests/README.txt | 3 + icu4j/perf-tests/pom.xml | 59 +++++++++++++++++++ .../perf/LowercaseTransliteratorPerf.java | 35 +++++++++++ 3 files changed, 97 insertions(+) create mode 100644 icu4j/perf-tests/src/main/java/com/ibm/icu/dev/test/perf/LowercaseTransliteratorPerf.java diff --git a/icu4j/perf-tests/README.txt b/icu4j/perf-tests/README.txt index d26f3fdafa5..7e96f9f87e3 100644 --- a/icu4j/perf-tests/README.txt +++ b/icu4j/perf-tests/README.txt @@ -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 diff --git a/icu4j/perf-tests/pom.xml b/icu4j/perf-tests/pom.xml index a4debcade13..b580e37c572 100644 --- a/icu4j/perf-tests/pom.xml +++ b/icu4j/perf-tests/pom.xml @@ -15,6 +15,7 @@ perf_tests + 1.37 @@ -43,6 +44,64 @@ commons-cli ${commons-cli.version} + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.openjdk.jmh.generators.BenchmarkProcessor + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + jmh-benchmarks + + + org.openjdk.jmh.Main + + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + diff --git a/icu4j/perf-tests/src/main/java/com/ibm/icu/dev/test/perf/LowercaseTransliteratorPerf.java b/icu4j/perf-tests/src/main/java/com/ibm/icu/dev/test/perf/LowercaseTransliteratorPerf.java new file mode 100644 index 00000000000..26baea593f0 --- /dev/null +++ b/icu4j/perf-tests/src/main/java/com/ibm/icu/dev/test/perf/LowercaseTransliteratorPerf.java @@ -0,0 +1,35 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +/* + ********************************************************************** + * Copyright (c) 2002-2008, International Business Machines * + * Corporation and others. All Rights Reserved. * + ********************************************************************** + */ +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"); + } + +}