diff options
Diffstat (limited to 'benchmarks')
13 files changed, 76 insertions, 786 deletions
diff --git a/benchmarks/Android.mk b/benchmarks/Android.mk index b73f167bc2..623ba9c6fc 100644 --- a/benchmarks/Android.mk +++ b/benchmarks/Android.mk @@ -27,10 +27,7 @@ LOCAL_JAVA_LIBRARIES := \ caliper-api-target \ core-oj \ core-libart \ - conscrypt \ - android.test.base \ - bouncycastle \ - framework + android.test.base LOCAL_MODULE_TAGS := tests LOCAL_MODULE_PATH := $(PRODUCT_OUT)/data/caliperperf LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk diff --git a/benchmarks/src/benchmarks/DeepArrayOpsBenchmark.java b/benchmarks/src/benchmarks/DeepArrayOpsBenchmark.java index 142906211b..c671da6f41 100644 --- a/benchmarks/src/benchmarks/DeepArrayOpsBenchmark.java +++ b/benchmarks/src/benchmarks/DeepArrayOpsBenchmark.java @@ -16,24 +16,23 @@ package benchmarks; +import com.google.caliper.BeforeExperiment; +import com.google.caliper.Benchmark; import com.google.caliper.Param; import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.util.Arrays; public class DeepArrayOpsBenchmark { - @Param({"1", "4", "16", "256", "2048"}) int arrayLength; + @Param({"0001", "0004", "0016", "0256", "2048"}) int arrayLength; private Object[] array; private Object[] array2; - private Object[] array3; - private Object[] array4; - - protected void setUp() throws Exception { - array = new Object[arrayLength * 13]; - array2 = new Object[arrayLength * 13]; - for (int i = 0; i < arrayLength; i += 13) { + @BeforeExperiment public void setUp() throws Exception { + array = new Object[arrayLength * 14]; + array2 = new Object[arrayLength * 14]; + for (int i = 0; i < arrayLength; i += 14) { array[i] = new IntWrapper(i); array2[i] = new IntWrapper(i); @@ -74,16 +73,19 @@ public class DeepArrayOpsBenchmark { // Subarray types is an interface. array[i + 12] = new16ElementArray(CharSequence.class, String.class); array2[i + 12] = new16ElementArray(CharSequence.class, String.class); + + array[i + 13] = null; + array2[i + 13] = null; } } - public void timeDeepHashCode(int reps) { + @Benchmark public void deepHashCode(int reps) { for (int i = 0; i < reps; ++i) { Arrays.deepHashCode(array); } } - public void timeEquals(int reps) { + @Benchmark public void deepEquals(int reps) { for (int i = 0; i < reps; ++i) { Arrays.deepEquals(array, array2); } @@ -143,4 +145,3 @@ public class DeepArrayOpsBenchmark { } } } - diff --git a/benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java b/benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java deleted file mode 100644 index 2e85fae040..0000000000 --- a/benchmarks/src/benchmarks/GetInstancesOfClassesBenchmark.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2017 Google Inc. - * - * 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 - * - * http://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 benchmarks; - -import dalvik.system.VMDebug; - -public class GetInstancesOfClassesBenchmark { - private static class ObjectTree { - ObjectTree left; - ObjectTree right; - - public ObjectTree(int depth) { - if (depth > 1) { - left = new ObjectTree(depth - 1); - right = new ObjectTree(depth - 1); - } - } - } - - // 2^19 = 524288 - private static ObjectTree tree = new ObjectTree(19); - - public void timeGetInstancesOf1Class(int reps) { - Class[] classes = new Class[]{ - Integer.class - }; - for (int rep = 0; rep < reps; ++rep) { - VMDebug.getInstancesOfClasses(classes, true); - } - } - - public void timeGetInstancesOf2Classes(int reps) { - Class[] classes = new Class[]{ - Integer.class, - Long.class - }; - for (int rep = 0; rep < reps; ++rep) { - VMDebug.getInstancesOfClasses(classes, true); - } - } - - public void timeGetInstancesOf4Classes(int reps) { - Class[] classes = new Class[]{ - Integer.class, - Long.class, - Float.class, - Double.class - }; - for (int rep = 0; rep < reps; ++rep) { - VMDebug.getInstancesOfClasses(classes, true); - } - } -} diff --git a/benchmarks/src/benchmarks/GetSystemPropertyBenchmark.java b/benchmarks/src/benchmarks/GetSystemPropertyBenchmark.java new file mode 100644 index 0000000000..3a93285db3 --- /dev/null +++ b/benchmarks/src/benchmarks/GetSystemPropertyBenchmark.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 + * + * http://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 benchmarks; + +import java.security.AccessController; + +import sun.security.action.GetPropertyAction; + +/** + * Compares performance of accessing system properties via + * legacy security code + * {@code AccessController.doPrivileged(new GetPropertyAction(key[, default]))} + * vs. direct invocation of {@code System.getProperty(key[, default])}. + * + * As of 2018-07, libcore carries some patches to perform such short-circuiting, + * so it's interesting to know how much better it performs. + */ +public class GetSystemPropertyBenchmark { + + public void timeSystem_getProperty_default(int reps) { + for (int i = 0; i < reps; i++) { + System.getProperty("user.language", "en"); + } + } + + public void timeSystem_getProperty(int reps) { + for (int i = 0; i < reps; i++) { + System.getProperty("user.region"); + } + } + + public void timeAccessController_getPropertyAction(int reps) { + for (int i = 0; i < reps; i++) { + AccessController.doPrivileged( + new GetPropertyAction("user.language", "en")); + } + } + + public void timeAccessController_getPropertyAction_default(int reps) { + for (int i = 0; i < reps; i++) { + AccessController.doPrivileged( + new GetPropertyAction("user.region")); + } + } + +} diff --git a/benchmarks/src/benchmarks/XmlParseBenchmark.java b/benchmarks/src/benchmarks/XmlParseBenchmark.java index 69ab7a5dce..1029616d3d 100644 --- a/benchmarks/src/benchmarks/XmlParseBenchmark.java +++ b/benchmarks/src/benchmarks/XmlParseBenchmark.java @@ -65,7 +65,8 @@ public class XmlParseBenchmark { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); documentBuilder = builderFactory.newDocumentBuilder(); - kxmlConstructor = (Constructor) Class.forName("org.kxml2.io.KXmlParser").getConstructor(); + kxmlConstructor = (Constructor) Class.forName("com.android.org.kxml2.io.KXmlParser") + .getConstructor(); expatConstructor = (Constructor) Class.forName("org.apache.harmony.xml.ExpatPullParser") .getConstructor(); } diff --git a/benchmarks/src/benchmarks/XmlSerializeBenchmark.java b/benchmarks/src/benchmarks/XmlSerializeBenchmark.java index c542e87ce0..a8c51b395e 100644 --- a/benchmarks/src/benchmarks/XmlSerializeBenchmark.java +++ b/benchmarks/src/benchmarks/XmlSerializeBenchmark.java @@ -81,7 +81,7 @@ public class XmlSerializeBenchmark { @SuppressWarnings("unchecked") @BeforeExperiment protected void setUp() throws Exception { - kxmlConstructor = (Constructor) Class.forName("org.kxml2.io.KXmlSerializer") + kxmlConstructor = (Constructor) Class.forName("com.android.org.kxml2.io.KXmlSerializer") .getConstructor(); fastConstructor = (Constructor) Class.forName("com.android.internal.util.FastXmlSerializer") .getConstructor(); diff --git a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java b/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java deleted file mode 100644 index 3cde240a47..0000000000 --- a/benchmarks/src/benchmarks/regression/DateIntervalFormatBenchmark.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2013 Google Inc. - * - * 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 - * - * http://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 benchmarks.regression; - -import android.icu.util.TimeZone; -import android.icu.util.ULocale; -import libcore.icu.DateIntervalFormat; - -import static libcore.icu.DateUtilsBridge.*; - -public class DateIntervalFormatBenchmark { - public void timeDateIntervalFormat_formatDateRange_DATE(int reps) throws Exception { - ULocale l = ULocale.US; - TimeZone utc = TimeZone.getTimeZone("UTC"); - int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY; - - for (int rep = 0; rep < reps; ++rep) { - DateIntervalFormat.formatDateRange(l, utc, 0L, 0L, flags); - } - } - - public void timeDateIntervalFormat_formatDateRange_TIME(int reps) throws Exception { - ULocale l = ULocale.US; - TimeZone utc = TimeZone.getTimeZone("UTC"); - int flags = FORMAT_SHOW_TIME | FORMAT_24HOUR; - - for (int rep = 0; rep < reps; ++rep) { - DateIntervalFormat.formatDateRange(l, utc, 0L, 0L, flags); - } - } - - public void timeDateIntervalFormat_formatDateRange_DATE_TIME(int reps) throws Exception { - ULocale l = ULocale.US; - TimeZone utc = TimeZone.getTimeZone("UTC"); - int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_WEEKDAY | FORMAT_SHOW_TIME | FORMAT_24HOUR; - - for (int rep = 0; rep < reps; ++rep) { - DateIntervalFormat.formatDateRange(l, utc, 0L, 0L, flags); - } - } -} diff --git a/benchmarks/src/benchmarks/regression/DateToStringBenchmark.java b/benchmarks/src/benchmarks/regression/DateToStringBenchmark.java deleted file mode 100644 index 052fe38aa3..0000000000 --- a/benchmarks/src/benchmarks/regression/DateToStringBenchmark.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * 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 - * - * http://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 benchmarks.regression; - -import android.text.format.DateFormat; -import com.google.caliper.BeforeExperiment; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -public final class DateToStringBenchmark { - Date date; - Calendar calendar; - SimpleDateFormat format; - - @BeforeExperiment - protected void setUp() throws Exception { - date = new Date(0); - calendar = new GregorianCalendar(); - calendar.setTime(date); - format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); - } - - public void timeDateToString(int reps) throws Exception { - for (int i = 0; i < reps; ++i) { - date.toString(); - } - } - - public void timeDateToString_Formatter(int reps) throws Exception { - for (int i = 0; i < reps; ++i) { - new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").format(date); - } - } - - public void timeDateToString_ClonedFormatter(int reps) throws Exception { - for (int i = 0; i < reps; ++i) { - ((SimpleDateFormat) format.clone()).format(date); - } - } - - public void timeDateToString_AndroidDateFormat(int reps) { - for (int i = 0; i < reps; i++) { - DateFormat.format("EEE MMM dd HH:mm:ss zzz yyyy", calendar); - } - } -} diff --git a/benchmarks/src/benchmarks/regression/DigestBenchmark.java b/benchmarks/src/benchmarks/regression/DigestBenchmark.java deleted file mode 100644 index e576d87cd6..0000000000 --- a/benchmarks/src/benchmarks/regression/DigestBenchmark.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * 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 - * - * http://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 benchmarks.regression; - -import com.android.org.bouncycastle.crypto.Digest; -import com.google.caliper.BeforeExperiment; -import com.google.caliper.Param; - -public class DigestBenchmark { - - private static final int DATA_SIZE = 8192; - private static final byte[] DATA = new byte[DATA_SIZE]; - static { - for (int i = 0; i < DATA_SIZE; i++) { - DATA[i] = (byte)i; - } - } - - @Param private Algorithm algorithm; - - public enum Algorithm { MD5, SHA1, SHA256, SHA384, SHA512 }; - - @Param private Implementation implementation; - - public enum Implementation { OPENSSL, BOUNCYCASTLE }; - - private Class<? extends Digest> digestClass; - - @BeforeExperiment - protected void setUp() throws Exception { - String className = "com.android.org.bouncycastle.crypto.digests."; - switch (implementation) { - case OPENSSL: - className += ("OpenSSLDigest$" + algorithm); - break; - case BOUNCYCASTLE: - className += (algorithm + "Digest"); - break; - default: - throw new RuntimeException(implementation.toString()); - } - this.digestClass = (Class<? extends Digest>)Class.forName(className); - } - - public void time(int reps) throws Exception { - for (int i = 0; i < reps; ++i) { - Digest digest = digestClass.newInstance(); - digest.update(DATA, 0, DATA_SIZE); - digest.doFinal(new byte[digest.getDigestSize()], 0); - } - } -} diff --git a/benchmarks/src/benchmarks/regression/IcuBenchmark.java b/benchmarks/src/benchmarks/regression/IcuBenchmark.java deleted file mode 100644 index 47661b8bbe..0000000000 --- a/benchmarks/src/benchmarks/regression/IcuBenchmark.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2013 Google Inc. - * - * 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 - * - * http://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 benchmarks.regression; - -import java.util.Locale; -import libcore.icu.ICU; - -public class IcuBenchmark { - - 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); - } - } - -} diff --git a/benchmarks/src/benchmarks/regression/ParseBenchmark.java b/benchmarks/src/benchmarks/regression/ParseBenchmark.java deleted file mode 100644 index 8f52a34790..0000000000 --- a/benchmarks/src/benchmarks/regression/ParseBenchmark.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. - * - * 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 - * - * http://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 benchmarks.regression; - -import com.google.caliper.BeforeExperiment; -import com.google.caliper.Param; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.SAXParserFactory; -import org.json.JSONArray; -import org.json.JSONObject; -import org.xml.sax.InputSource; -import org.xml.sax.helpers.DefaultHandler; -import org.xmlpull.v1.XmlPullParser; - -/** - * Measure throughput of various parsers. - * - * <p>This benchmark requires that ParseBenchmarkData.zip is on the classpath. - * That file contains Twitter feed data, which is representative of what - * applications will be parsing. - */ -public final class ParseBenchmark { - - @Param Document document; - @Param Api api; - - private enum Document { - TWEETS, - READER_SHORT, - READER_LONG - } - - private enum Api { - ANDROID_STREAM("json") { - @Override Parser newParser() { - return new AndroidStreamParser(); - } - }, - ORG_JSON("json") { - @Override Parser newParser() { - return new OrgJsonParser(); - } - }, - XML_PULL("xml") { - @Override Parser newParser() { - return new GeneralXmlPullParser(); - } - }, - XML_DOM("xml") { - @Override Parser newParser() { - return new XmlDomParser(); - } - }, - XML_SAX("xml") { - @Override Parser newParser() { - return new XmlSaxParser(); - } - }; - - final String extension; - - private Api(String extension) { - this.extension = extension; - } - - abstract Parser newParser(); - } - - private String text; - private Parser parser; - - @BeforeExperiment - protected void setUp() throws Exception { - text = resourceToString("/" + document.name() + "." + api.extension); - parser = api.newParser(); - } - - public void timeParse(int reps) throws Exception { - for (int i = 0; i < reps; i++) { - parser.parse(text); - } - } - - private static String resourceToString(String path) throws Exception { - InputStream in = ParseBenchmark.class.getResourceAsStream(path); - if (in == null) { - throw new IllegalArgumentException("No such file: " + path); - } - - Reader reader = new InputStreamReader(in, "UTF-8"); - char[] buffer = new char[8192]; - StringWriter writer = new StringWriter(); - int count; - while ((count = reader.read(buffer)) != -1) { - writer.write(buffer, 0, count); - } - reader.close(); - return writer.toString(); - } - - interface Parser { - void parse(String data) throws Exception; - } - - private static class AndroidStreamParser implements Parser { - @Override public void parse(String data) throws Exception { - android.util.JsonReader jsonReader - = new android.util.JsonReader(new StringReader(data)); - readToken(jsonReader); - jsonReader.close(); - } - - public void readObject(android.util.JsonReader reader) throws IOException { - reader.beginObject(); - while (reader.hasNext()) { - reader.nextName(); - readToken(reader); - } - reader.endObject(); - } - - public void readArray(android.util.JsonReader reader) throws IOException { - reader.beginArray(); - while (reader.hasNext()) { - readToken(reader); - } - reader.endArray(); - } - - private void readToken(android.util.JsonReader reader) throws IOException { - switch (reader.peek()) { - case BEGIN_ARRAY: - readArray(reader); - break; - case BEGIN_OBJECT: - readObject(reader); - break; - case BOOLEAN: - reader.nextBoolean(); - break; - case NULL: - reader.nextNull(); - break; - case NUMBER: - reader.nextLong(); - break; - case STRING: - reader.nextString(); - break; - default: - throw new IllegalArgumentException("Unexpected token" + reader.peek()); - } - } - } - - private static class OrgJsonParser implements Parser { - @Override public void parse(String data) throws Exception { - if (data.startsWith("[")) { - new JSONArray(data); - } else if (data.startsWith("{")) { - new JSONObject(data); - } else { - throw new IllegalArgumentException(); - } - } - } - - private static class GeneralXmlPullParser implements Parser { - @Override public void parse(String data) throws Exception { - XmlPullParser xmlParser = android.util.Xml.newPullParser(); - xmlParser.setInput(new StringReader(data)); - xmlParser.nextTag(); - while (xmlParser.next() != XmlPullParser.END_DOCUMENT) { - xmlParser.getName(); - xmlParser.getText(); - } - } - } - - private static class XmlDomParser implements Parser { - @Override public void parse(String data) throws Exception { - DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse(new InputSource(new StringReader(data))); - } - } - - private static class XmlSaxParser implements Parser { - @Override public void parse(String data) throws Exception { - SAXParserFactory.newInstance().newSAXParser().parse( - new InputSource(new StringReader(data)), new DefaultHandler()); - } - } -} diff --git a/benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java b/benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java deleted file mode 100644 index 6ddbc77279..0000000000 --- a/benchmarks/src/benchmarks/regression/RelativeDateTimeFormatterBenchmark.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * 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 - * - * http://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 benchmarks.regression; - -import java.util.Locale; -import java.util.TimeZone; - -import static libcore.icu.DateUtilsBridge.FORMAT_ABBREV_RELATIVE; -import static libcore.icu.RelativeDateTimeFormatter.getRelativeDateTimeString; -import static libcore.icu.RelativeDateTimeFormatter.getRelativeTimeSpanString; - -public class RelativeDateTimeFormatterBenchmark { - public void timeRelativeDateTimeFormatter_getRelativeTimeSpanString(int reps) throws Exception { - Locale l = Locale.US; - TimeZone utc = TimeZone.getTimeZone("Europe/London"); - int flags = 0; - - for (int rep = 0; rep < reps; ++rep) { - getRelativeTimeSpanString(l, utc, 0L, 0L, 0L, flags); - } - } - - public void timeRelativeDateTimeFormatter_getRelativeTimeSpanString_ABBREV(int reps) throws Exception { - Locale l = Locale.US; - TimeZone utc = TimeZone.getTimeZone("UTC"); - int flags = FORMAT_ABBREV_RELATIVE; - - for (int rep = 0; rep < reps; ++rep) { - getRelativeTimeSpanString(l, utc, 0L, 0L, 0L, flags); - } - } - - public void timeRelativeDateTimeFormatter_getRelativeDateTimeString(int reps) throws Exception { - Locale l = Locale.US; - TimeZone utc = TimeZone.getTimeZone("UTC"); - int flags = 0; - - for (int rep = 0; rep < reps; ++rep) { - getRelativeDateTimeString(l, utc, 0L, 0L, 0L, 0L, flags); - } - } - - public void timeRelativeDateTimeFormatter_getRelativeDateTimeString_ABBREV(int reps) throws Exception { - Locale l = Locale.US; - TimeZone utc = TimeZone.getTimeZone("America/Los_Angeles"); - int flags = FORMAT_ABBREV_RELATIVE; - - for (int rep = 0; rep < reps; ++rep) { - getRelativeDateTimeString(l, utc, 0L, 0L, 0L, 0L, flags); - } - } -} diff --git a/benchmarks/src/benchmarks/regression/StringCaseMappingBenchmark.java b/benchmarks/src/benchmarks/regression/StringCaseMappingBenchmark.java deleted file mode 100644 index 16931572c6..0000000000 --- a/benchmarks/src/benchmarks/regression/StringCaseMappingBenchmark.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. - * - * 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 - * - * http://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 benchmarks.regression; - -import com.google.caliper.Param; -import java.util.Locale; - -public class StringCaseMappingBenchmark { - enum Inputs { - EMPTY(""), - - // TODO: include hairy inputs like turkish and greek. - // TODO: locale makes a difference too. - - LOWER2(lower(2)), - UPPER2(upper(2)), - MIXED2(mixed(2)), - - LOWER8(lower(8)), - UPPER8(upper(8)), - MIXED8(mixed(8)), - - LOWER32(lower(32)), - UPPER32(upper(32)), - MIXED32(mixed(32)), - - LOWER512(lower(512)), - UPPER512(upper(512)), - MIXED512(mixed(512)), - - LOWER2048(lower(2048)), - UPPER2048(upper(2048)), - MIXED2048(mixed(2048)), - - LOWER_1M(lower(1024*1024)), - UPPER_1M(upper(1024*1024)), - MIXED_1M(mixed(1024*1024)); - - final String value; - private Inputs(String value) { this.value = value; } - private static String lower(int length) { - return makeString(length, "a0b1c2d3e4f5g6h7i8j9klmnopqrstuvwxyz"); - } - private static String upper(int length) { - return makeString(length, "A0B1C2D3E4F5G6H7I8J9KLMNOPQRSTUVWXYZ"); - } - private static String mixed(int length) { - return makeString(length, "Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7Ii8Jj9KkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"); - } - private static String makeString(int length, String alphabet) { - StringBuilder sb = new StringBuilder(length); - for (int i = 0; i < length; ++i) { - sb.append(alphabet.charAt(i % alphabet.length())); - } - return sb.toString(); - } - } - @Param private Inputs s; - - public void timeToUpperCase_US(int reps) { - for (int i = 0; i < reps; ++i) { - s.value.toUpperCase(Locale.US); - } - } - - // toUpperCase for Greek is an extra-hard case that uses icu4c's Transliterator. - public void timeToUpperCase_el_GR(int reps) { - Locale el_GR = new Locale("el", "GR"); - for (int i = 0; i < reps; ++i) { - s.value.toUpperCase(el_GR); - } - } - - public void timeToLowerCase_US(int reps) { - for (int i = 0; i < reps; ++i) { - s.value.toLowerCase(Locale.US); - } - } - - public void timeToUpperCase_Ascii(int reps) { - for (int i = 0; i < reps; ++i) { - toUpperCaseAscii(s.value); - } - } - - public void timeToLowerCase_Ascii(int reps) { - for (int i = 0; i < reps; ++i) { - toLowerCaseAscii(s.value); - } - } - - public void timeToUpperCase_ICU(int reps) { - for (int i = 0; i < reps; ++i) { - libcore.icu.ICU.toUpperCase(s.value, Locale.US); - } - } - - public void timeToLowerCase_ICU(int reps) { - for (int i = 0; i < reps; ++i) { - libcore.icu.ICU.toLowerCase(s.value, Locale.US); - } - } - - public static String toUpperCaseAscii(String s) { - for (int i = 0, length = s.length(); i < length; i++) { - char c = s.charAt(i); - if (c < 'a' || c > 'z') { - continue; // fast path avoids allocation - } - - // slow path: s contains lower case chars - char[] result = s.toCharArray(); - for (; i < length; i++) { - c = result[i]; - if (c >= 'a' && c <= 'z') { - result[i] -= ('a' - 'A'); - } - } - return new String(result); - } - return s; - } - - public static String toLowerCaseAscii(String s) { - for (int i = 0, length = s.length(); i < length; i++) { - char c = s.charAt(i); - if (c < 'A' || c > 'Z') { - continue; // fast path avoids allocation - } - - // slow path: s contains upper case chars - char[] result = s.toCharArray(); - for (; i < length; i++) { - c = result[i]; - if (c >= 'A' && c <= 'Z') { - result[i] += ('a' - 'A'); - } - } - return new String(result); - } - return s; - } -} |