Add benchmark for case conversion.
The base benchmarks using ICU4C are as follows.
_toLowerCaseAsciiUs 11.28 ====================
_toUpperCaseAsciiUS 11.15 ====================
_toUpperCaseLat1SuplFr 12.27 ======================
_toUpperCaseLatExtACz 13.92 =========================
_toUpperCaseLatExtBPinyin 16.35 ==============================
Temporarily changing ICU.toUpperCase to call
icu.lang.UCharacter.toUpperCase
_toLowerCaseAsciiUs 11.19 ===
_toUpperCaseAsciiUS 17.33 ====
_toUpperCaseLat1SuplFr 40.18 ===========
_toUpperCaseLatExtACz 69.09 ===================
_toUpperCaseLatExtBPinyin 108.47 ==============================
Please enter the commit message for your changes. Lines starting
Change-Id: I58c2404d03e539c4c8732bd5238022ec66712a31
diff --git a/benchmarks/src/benchmarks/regression/IcuBenchmark.java b/benchmarks/src/benchmarks/regression/IcuBenchmark.java
index 2aed36b..36014f2 100644
--- a/benchmarks/src/benchmarks/regression/IcuBenchmark.java
+++ b/benchmarks/src/benchmarks/regression/IcuBenchmark.java
@@ -19,14 +19,68 @@
import com.google.caliper.SimpleBenchmark;
import java.util.Locale;
-import java.util.TimeZone;
import libcore.icu.ICU;
public class IcuBenchmark extends SimpleBenchmark {
- public void time_getBestDateTimePattern(int reps) throws Exception {
- for (int rep = 0; rep < reps; ++rep) {
- ICU.getBestDateTimePattern("dEEEMMM", new Locale("en", "US"));
+
+ private static final String ASCII_LOWERCASE = makeUnicodeRange(97, 122);
+ private static final String ASCII_UPPERCASE = makeUnicodeRange(65, 90);
+
+ private static final String LAT_1_SUPPLEMENT = makeUnicodeRange(0xC0, 0xFF);
+ private static final String LAT_EXTENDED_A = makeUnicodeRange(0x100, 0x17F);
+ private static final String LAT_EXTENDED_B = makeUnicodeRange(0x180, 0x24F);
+
+ private static final Locale CZECH_LOCALE = Locale.forLanguageTag("cs-CZ");
+ private static final Locale PINYIN_LOCALE = Locale.forLanguageTag("zh-Latn");
+
+ public static String makeUnicodeRange(int startingCodePoint, int endingCodePoint) {
+ char[] tmp = new char[endingCodePoint - startingCodePoint + 1];
+ for (int i = startingCodePoint; i <= endingCodePoint; i++) {
+ tmp[i - startingCodePoint] = (char) i;
+ }
+ return new String(tmp);
}
- }
+
+ public void time_getBestDateTimePattern(int reps) throws Exception {
+ for (int rep = 0; rep < reps; ++rep) {
+ ICU.getBestDateTimePattern("dEEEMMM", new Locale("en", "US"));
+ }
+ }
+
+ // Convert standard lowercase ASCII characters to uppercase using ICU4C in the US locale.
+ public void time_toUpperCaseAsciiUS(int reps) {
+ for (int i = 0; i < reps; i++) {
+ ICU.toUpperCase(ASCII_LOWERCASE, Locale.US);
+ }
+ }
+
+ // Convert standard uppercase ASCII characters to lowercase.
+ public void time_toLowerCaseAsciiUs(int reps) {
+ for (int i = 0; i < reps; i++) {
+ ICU.toLowerCase(ASCII_UPPERCASE, Locale.US);
+ }
+ }
+
+ // Convert Latin 1 supplement characters to uppercase in France locale.
+ public void time_toUpperCaseLat1SuplFr(int reps) {
+ for (int i = 0; i < reps; i++) {
+ ICU.toUpperCase(LAT_1_SUPPLEMENT, Locale.FRANCE);
+ }
+ }
+
+ // Convert Latin Extension A characters to uppercase in Czech locale
+ public void time_toUpperCaseLatExtACz(int reps) {
+ for (int i = 0; i < reps; i++) {
+ ICU.toUpperCase(LAT_EXTENDED_A, CZECH_LOCALE);
+ }
+ }
+
+ // Convert Latin Extension B characters to uppercase in Pinyin locale.
+ public void time_toUpperCaseLatExtBPinyin(int reps) {
+ for (int i = 0; i < reps; i++) {
+ ICU.toUpperCase(LAT_EXTENDED_B, PINYIN_LOCALE);
+ }
+ }
+
}