Merge "Even more libcore benchmark tests."
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/AnnotatedElementPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/AnnotatedElementPerfTest.java
new file mode 100644
index 0000000..d38d519
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/AnnotatedElementPerfTest.java
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class AnnotatedElementPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private Class<?> mType;
+ private Field mField;
+ private Method mMethod;
+
+ @Before
+ public void setUp() throws Exception {
+ mType = Type.class;
+ mField = Type.class.getField("field");
+ mMethod = Type.class.getMethod("method", String.class);
+ }
+
+ // get annotations by member type and method
+
+ @Test
+ public void timeGetTypeAnnotations() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mType.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetFieldAnnotations() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mField.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetMethodAnnotations() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mMethod.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetParameterAnnotations() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mMethod.getParameterAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetTypeAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mType.getAnnotation(Marker.class);
+ }
+ }
+
+ @Test
+ public void timeGetFieldAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mField.getAnnotation(Marker.class);
+ }
+ }
+
+ @Test
+ public void timeGetMethodAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mMethod.getAnnotation(Marker.class);
+ }
+ }
+
+ @Test
+ public void timeIsTypeAnnotationPresent() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mType.isAnnotationPresent(Marker.class);
+ }
+ }
+
+ @Test
+ public void timeIsFieldAnnotationPresent() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mField.isAnnotationPresent(Marker.class);
+ }
+ }
+
+ @Test
+ public void timeIsMethodAnnotationPresent() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mMethod.isAnnotationPresent(Marker.class);
+ }
+ }
+
+ // get annotations by result size
+
+ @Test
+ public void timeGetAllReturnsLargeAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasLargeAnnotation.class.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetAllReturnsSmallAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasSmallAnnotation.class.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetAllReturnsMarkerAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasMarkerAnnotation.class.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetAllReturnsNoAnnotation() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasNoAnnotations.class.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetAllReturnsThreeAnnotations() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasThreeAnnotations.class.getAnnotations();
+ }
+ }
+
+ // get annotations with inheritance
+
+ @Test
+ public void timeGetAnnotationsOnSubclass() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ ExtendsHasThreeAnnotations.class.getAnnotations();
+ }
+ }
+
+ @Test
+ public void timeGetDeclaredAnnotationsOnSubclass() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ ExtendsHasThreeAnnotations.class.getDeclaredAnnotations();
+ }
+ }
+
+ // get annotations with enclosing / inner classes
+
+ @Test
+ public void timeGetDeclaredClasses() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ AnnotatedElementPerfTest.class.getDeclaredClasses();
+ }
+ }
+
+ @Test
+ public void timeGetDeclaringClass() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasSmallAnnotation.class.getDeclaringClass();
+ }
+ }
+
+ @Test
+ public void timeGetEnclosingClass() {
+ Object anonymousClass = new Object() {};
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ anonymousClass.getClass().getEnclosingClass();
+ }
+ }
+
+ @Test
+ public void timeGetEnclosingConstructor() {
+ Object anonymousClass = new Object() {};
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ anonymousClass.getClass().getEnclosingConstructor();
+ }
+ }
+
+ @Test
+ public void timeGetEnclosingMethod() {
+ Object anonymousClass = new Object() {};
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ anonymousClass.getClass().getEnclosingMethod();
+ }
+ }
+
+ @Test
+ public void timeGetModifiers() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasSmallAnnotation.class.getModifiers();
+ }
+ }
+
+ @Test
+ public void timeGetSimpleName() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasSmallAnnotation.class.getSimpleName();
+ }
+ }
+
+ @Test
+ public void timeIsAnonymousClass() {
+ Object anonymousClass = new Object() {};
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ anonymousClass.getClass().isAnonymousClass();
+ }
+ }
+
+ @Test
+ public void timeIsLocalClass() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ HasSmallAnnotation.class.isLocalClass();
+ }
+ }
+
+ // the annotated elements
+
+ @Marker
+ public class Type {
+ @Marker public String field;
+
+ @Marker
+ public void method(@Marker String parameter) {}
+ }
+
+ @Large(
+ a = "on class",
+ b = {"A", "B", "C"},
+ c = @Small(e = "E1", f = 1695938256, g = 7264081114510713000L),
+ d = {@Small(e = "E2", f = 1695938256, g = 7264081114510713000L)})
+ public class HasLargeAnnotation {}
+
+ @Small(e = "E1", f = 1695938256, g = 7264081114510713000L)
+ public class HasSmallAnnotation {}
+
+ @Marker
+ public class HasMarkerAnnotation {}
+
+ public class HasNoAnnotations {}
+
+ @Large(
+ a = "on class",
+ b = {"A", "B", "C"},
+ c = @Small(e = "E1", f = 1695938256, g = 7264081114510713000L),
+ d = {@Small(e = "E2", f = 1695938256, g = 7264081114510713000L)})
+ @Small(e = "E1", f = 1695938256, g = 7264081114510713000L)
+ @Marker
+ public class HasThreeAnnotations {}
+
+ public class ExtendsHasThreeAnnotations extends HasThreeAnnotations {}
+
+ // the annotations
+
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Marker {}
+
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Large {
+ String a() default "";
+
+ String[] b() default {};
+
+ Small c() default @Small;
+
+ Small[] d() default {};
+ }
+
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Small {
+ String e() default "";
+
+ int f() default 0;
+
+ long g() default 0L;
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/BidiPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/BidiPerfTest.java
new file mode 100644
index 0000000..cc56868
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/BidiPerfTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.math.BigDecimal;
+import java.text.AttributedCharacterIterator;
+import java.text.Bidi;
+import java.text.DecimalFormat;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class BidiPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private static final AttributedCharacterIterator CHAR_ITER =
+ DecimalFormat.getInstance().formatToCharacterIterator(new BigDecimal(Math.PI));
+
+ @Test
+ public void time_createBidiFromIter() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi bidi = new Bidi(CHAR_ITER);
+ }
+ }
+
+ @Test
+ public void time_createBidiFromCharArray() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi bd =
+ new Bidi(
+ new char[] {'s', 's', 's'},
+ 0,
+ new byte[] {(byte) 1, (byte) 2, (byte) 3},
+ 0,
+ 3,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ }
+ }
+
+ @Test
+ public void time_createBidiFromString() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi bidi = new Bidi("Hello", Bidi.DIRECTION_LEFT_TO_RIGHT);
+ }
+ }
+
+ @Test
+ public void time_reorderVisually() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi.reorderVisually(
+ new byte[] {2, 1, 3, 0, 4}, 0, new String[] {"H", "e", "l", "l", "o"}, 0, 5);
+ }
+ }
+
+ @Test
+ public void time_hebrewBidi() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi bd =
+ new Bidi(
+ new char[] {'\u05D0', '\u05D0', '\u05D0'},
+ 0,
+ new byte[] {(byte) -1, (byte) -2, (byte) -3},
+ 0,
+ 3,
+ Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
+ bd =
+ new Bidi(
+ new char[] {'\u05D0', '\u05D0', '\u05D0'},
+ 0,
+ new byte[] {(byte) -1, (byte) -2, (byte) -3},
+ 0,
+ 3,
+ Bidi.DIRECTION_LEFT_TO_RIGHT);
+ }
+ }
+
+ @Test
+ public void time_complicatedOverrideBidi() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi bd =
+ new Bidi(
+ "a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(),
+ 0,
+ new byte[] {0, 0, 0, -3, -3, 2, 2, 0, 3},
+ 0,
+ 9,
+ Bidi.DIRECTION_RIGHT_TO_LEFT);
+ }
+ }
+
+ @Test
+ public void time_requiresBidi() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Bidi.requiresBidi("\u05D0".toCharArray(), 1, 1); // false.
+ Bidi.requiresBidi("\u05D0".toCharArray(), 0, 1); // true.
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/BigIntegerPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/BigIntegerPerfTest.java
new file mode 100644
index 0000000..662694b
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/BigIntegerPerfTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.math.BigInteger;
+import java.util.Random;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class BigIntegerPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Test
+ public void timeRandomDivision() throws Exception {
+ Random r = new Random();
+ BigInteger x = new BigInteger(1024, r);
+ BigInteger y = new BigInteger(1024, r);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ x.divide(y);
+ }
+ }
+
+ @Test
+ public void timeRandomGcd() throws Exception {
+ Random r = new Random();
+ BigInteger x = new BigInteger(1024, r);
+ BigInteger y = new BigInteger(1024, r);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ x.gcd(y);
+ }
+ }
+
+ @Test
+ public void timeRandomMultiplication() throws Exception {
+ Random r = new Random();
+ BigInteger x = new BigInteger(1024, r);
+ BigInteger y = new BigInteger(1024, r);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ x.multiply(y);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/BitSetPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/BitSetPerfTest.java
new file mode 100644
index 0000000..db5462c
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/BitSetPerfTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class BitSetPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "mSize={0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{1000}, {10000}});
+ }
+
+ @Parameterized.Parameter(0)
+ public int mSize;
+
+ private BitSet mBitSet;
+
+ @Before
+ public void setUp() throws Exception {
+ mBitSet = new BitSet(mSize);
+ }
+
+ @Test
+ public void timeIsEmptyTrue() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ if (!mBitSet.isEmpty()) throw new RuntimeException();
+ }
+ }
+
+ @Test
+ public void timeIsEmptyFalse() {
+ mBitSet.set(mBitSet.size() - 1);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ if (mBitSet.isEmpty()) throw new RuntimeException();
+ }
+ }
+
+ @Test
+ public void timeGet() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ int i = 1;
+ while (state.keepRunning()) {
+ mBitSet.get(++i % mSize);
+ }
+ }
+
+ @Test
+ public void timeClear() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ int i = 1;
+ while (state.keepRunning()) {
+ mBitSet.clear(++i % mSize);
+ }
+ }
+
+ @Test
+ public void timeSet() {
+ int i = 1;
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mBitSet.set(++i % mSize);
+ }
+ }
+
+ @Test
+ public void timeSetOn() {
+ int i = 1;
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mBitSet.set(++i % mSize, true);
+ }
+ }
+
+ @Test
+ public void timeSetOff() {
+ int i = 1;
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mBitSet.set(++i % mSize, false);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/BreakIteratorPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/BreakIteratorPerfTest.java
new file mode 100644
index 0000000..3952c12
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/BreakIteratorPerfTest.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2014 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.text.BreakIterator;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Locale;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public final class BreakIteratorPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ public enum Text {
+ LIPSUM(
+ Locale.US,
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis consequat"
+ + " nisl non pharetra. Praesent pretium vehicula odio sed ultrices. Aenean a"
+ + " felis libero. Vivamus sed commodo nibh. Pellentesque turpis lectus, euismod"
+ + " vel ante nec, cursus posuere orci. Suspendisse velit neque, fermentum"
+ + " luctus ultrices in, ultrices vitae arcu. Duis tincidunt cursus lorem. Nam"
+ + " ultricies accumsan quam vitae imperdiet. Pellentesque habitant morbi"
+ + " tristique senectus et netus et malesuada fames ac turpis egestas. Quisque"
+ + " aliquet pretium nisi, eget laoreet enim molestie sit amet. Class aptent"
+ + " taciti sociosqu ad litora torquent per conubia nostra, per inceptos"
+ + " himenaeos.\n"
+ + "Nam dapibus aliquam lacus ac suscipit. Proin in nibh sit amet purus congue"
+ + " laoreet eget quis nisl. Morbi gravida dignissim justo, a venenatis ante"
+ + " pulvinar at. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin"
+ + " ultrices vestibulum dui, vel aliquam lacus aliquam quis. Duis fringilla"
+ + " sapien ac lacus egestas, vel adipiscing elit euismod. Donec non tellus"
+ + " odio. Donec gravida eu massa ac feugiat. Aliquam erat volutpat. Praesent id"
+ + " adipiscing metus, nec laoreet enim. Aliquam vitae posuere turpis. Mauris ac"
+ + " pharetra sem. In at placerat tortor. Vivamus ac vehicula neque. Cras"
+ + " volutpat ullamcorper massa et varius. Praesent sagittis neque vitae nulla"
+ + " euismod pharetra.\n"
+ + "Sed placerat sapien non molestie sollicitudin. Nullam sit amet dictum quam."
+ + " Etiam tincidunt tortor vel pretium vehicula. Praesent fringilla ipsum vel"
+ + " velit luctus dignissim. Nulla massa ligula, mattis in enim et, mattis"
+ + " lacinia odio. Suspendisse tristique urna a orci commodo tempor. Duis"
+ + " lacinia egestas arcu a sollicitudin.\n"
+ + "In ac feugiat lacus. Nunc fermentum eu est at tristique. Pellentesque quis"
+ + " ligula et orci placerat lacinia. Maecenas quis mauris diam. Etiam mi ipsum,"
+ + " tempus in purus quis, euismod faucibus orci. Nulla facilisi. Praesent sit"
+ + " amet sapien vel elit porta adipiscing. Phasellus sit amet volutpat diam.\n"
+ + "Proin bibendum elit non lacus pharetra, quis eleifend tellus placerat. Nulla"
+ + " facilisi. Maecenas ante diam, pellentesque mattis mattis in, porta ut"
+ + " lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices"
+ + " posuere cubilia Curae; Nunc interdum tristique metus, in scelerisque odio"
+ + " fermentum eget. Cras nec venenatis lacus. Aenean euismod eget metus quis"
+ + " molestie. Cras tincidunt dolor ut massa ornare, in elementum lacus auctor."
+ + " Cras sodales nisl lacus, id ultrices ligula varius at. Sed tristique sit"
+ + " amet tellus vel mollis. Sed sed sollicitudin quam. Sed sed adipiscing"
+ + " risus, et dictum orci. Cras tempor pellentesque turpis et tempus."),
+ LONGPARA(
+ Locale.US,
+ "During dinner, Mr. Bennet scarcely spoke at all; but when the servants were"
+ + " withdrawn, he thought it time to have some conversation with his guest, and"
+ + " therefore started a subject in which he expected him to shine, by observing"
+ + " that he seemed very fortunate in his patroness. Lady Catherine de Bourgh's"
+ + " attention to his wishes, and consideration for his comfort, appeared very"
+ + " remarkable. Mr. Bennet could not have chosen better. Mr. Collins was"
+ + " eloquent in her praise. The subject elevated him to more than usual"
+ + " solemnity of manner, and with a most important aspect he protested that"
+ + " \"he had never in his life witnessed such behaviour in a person of"
+ + " rank--such affability and condescension, as he had himself experienced from"
+ + " Lady Catherine. She had been graciously pleased to approve of both of the"
+ + " discourses which he had already had the honour of preaching before her. She"
+ + " had also asked him twice to dine at Rosings, and had sent for him only the"
+ + " Saturday before, to make up her pool of quadrille in the evening. Lady"
+ + " Catherine was reckoned proud by many people he knew, but _he_ had never"
+ + " seen anything but affability in her. She had always spoken to him as she"
+ + " would to any other gentleman; she made not the smallest objection to his"
+ + " joining in the society of the neighbourhood nor to his leaving the parish"
+ + " occasionally for a week or two, to visit his relations. She had even"
+ + " condescended to advise him to marry as soon as he could, provided he chose"
+ + " with discretion; and had once paid him a visit in his humble parsonage,"
+ + " where she had perfectly approved all the alterations he had been making,"
+ + " and had even vouchsafed to suggest some herself--some shelves in the closet"
+ + " up stairs.\""),
+ GERMAN(
+ Locale.GERMANY,
+ "Aber dieser Freiheit setzte endlich der Winter ein Ziel. Draußen auf den Feldern"
+ + " und den hohen Bergen lag der Schnee und Peter wäre in seinem dünnen"
+ + " Leinwandjäckchen bald erfroren. Es war also seine einzige Freude, hinaus"
+ + " vor die Hütte zu treten und den Sperlingen Brotkrümchen zu streuen, was er"
+ + " sich jedesmal an seinem Frühstück absparte. Wenn nun die Vögel so lustig"
+ + " zwitscherten und um ihn herumflogen, da klopfte ihm das Herz vor Lust, und"
+ + " oft gab er ihnen sein ganzes Stück Schwarzbrot, ohne daran zu denken, daß"
+ + " er dafür alsdann selbst hungern müsse."),
+ THAI(
+ Locale.forLanguageTag("th-TH"),
+ "เป็นสำเนียงทางการของภาษาไทย"
+ + " เดิมทีเป็นการผสมผสานกันระหว่างสำเนียงอยุธยาและชาวไทยเชื้อสายจีนรุ่นหลังที่"
+ + "พูดไทยแทนกลุ่มภาษาจีน"
+ + " ลักษณะเด่นคือมีการออกเสียงที่ชัดเจนและแข็งกระด้างซึ่งได้รับอิทธิพลจากภาษาแต"
+ + "้จิ๋ว"
+ + " การออกเสียงพยัญชนะ สระ การผันวรรณยุกต์ที่ในภาษาไทยมาตรฐาน"
+ + " มาจากสำเนียงถิ่นนี้ในขณะที่ภาษาไทยสำเนียงอื่นล้วนเหน่อทั้งสิ้น"
+ + " คำศัพท์ที่ใช้ในสำเนียงกรุงเทพจำนวนมากได้รับมาจากกลุ่มภาษาจีนเช่นคำว่า โป๊,"
+ + " เฮ็ง, อาหมวย, อาซิ่ม ซึ่งมาจากภาษาแต้จิ๋ว และจากภาษาจีนเช่น ถู(涂), ชิ่ว(去"
+ + " อ่านว่า\"ชู่\") และคำว่า ทาย(猜 อ่านว่า \"ชาย\") เป็นต้น"
+ + " เนื่องจากสำเนียงกรุงเทพได้รับอิทธิพลมาจากภาษาจีนดังนั้นตัวอักษร \"ร\""
+ + " มักออกเสียงเหมารวมเป็น \"ล\" หรือคำควบกล่ำบางคำถูกละทิ้งไปด้วยเช่น รู้ เป็น"
+ + " ลู้, เรื่อง เป็น เลื่อง หรือ ประเทศ เป็น ปะเทศ"
+ + " เป็นต้นสร้างความลำบากให้แก่ต่างชาติที่ต้องการเรียนภาษาไทย"
+ + " แต่อย่างไรก็ตามผู้ที่พูดสำเนียงถิ่นนี้ก็สามารถออกอักขระภาษาไทยตามมาตรฐานได"
+ + "้อย่างถูกต้องเพียงแต่มักเผลอไม่ค่อยออกเสียง"),
+ THAI2(Locale.forLanguageTag("th-TH"), "this is the word browser in Thai: เบราว์เซอร์"),
+ TABS(Locale.US, "one\t\t\t\t\t\t\t\t\t\t\t\t\t\ttwo\n"),
+ ACCENT(Locale.US, "e\u0301\u00e9\nwhich is:\n\"e\\u0301\\u00e9\""),
+ EMOJI(Locale.US, ">>\ud83d\ude01<<\nwhich is:\n\">>\\ud83d\\ude01<<\""),
+ SPACES(Locale.US, " leading spaces and trailing ones too "),
+ EMPTY(Locale.US, ""),
+ NEWLINE(Locale.US, "\\n:\n"),
+ BIDI(
+ Locale.forLanguageTag("he-IL"),
+ "Sarah שרה is spelled sin ש resh ר heh ה from right to left.");
+
+ final Locale mLocale;
+ final String mText;
+
+ Text(Locale locale, String text) {
+ this.mText = text;
+ this.mLocale = locale;
+ }
+ }
+
+ @Parameters(name = "mText={0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {Text.ACCENT}, {Text.BIDI}, {Text.EMOJI}, {Text.EMPTY}, {Text.GERMAN},
+ {Text.LIPSUM}, {Text.LONGPARA}, {Text.NEWLINE}, {Text.SPACES}, {Text.TABS},
+ {Text.THAI}, {Text.THAI2}
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public Text mText;
+
+ @Test
+ public void timeBreakIterator() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ BreakIterator it = BreakIterator.getLineInstance(mText.mLocale);
+ it.setText(mText.mText);
+
+ while (it.next() != BreakIterator.DONE) {
+ // Keep iterating
+ }
+ }
+ }
+
+ @Test
+ public void timeIcuBreakIterator() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ android.icu.text.BreakIterator it =
+ android.icu.text.BreakIterator.getLineInstance(mText.mLocale);
+ it.setText(mText.mText);
+
+ while (it.next() != android.icu.text.BreakIterator.DONE) {
+ // Keep iterating
+ }
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferBulkPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferBulkPerfTest.java
new file mode 100644
index 0000000..8e57b28
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferBulkPerfTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class ByteBufferBulkPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "mAligned({0}), mSrcBufferType({1}), mDataBufferType({2}), mBufferSize({3})")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {true, MyBufferType.DIRECT, MyBufferType.DIRECT, 4096},
+ {false, MyBufferType.DIRECT, MyBufferType.DIRECT, 4096},
+ {true, MyBufferType.HEAP, MyBufferType.DIRECT, 4096},
+ {false, MyBufferType.HEAP, MyBufferType.DIRECT, 4096},
+ {true, MyBufferType.MAPPED, MyBufferType.DIRECT, 4096},
+ {false, MyBufferType.MAPPED, MyBufferType.DIRECT, 4096},
+ {true, MyBufferType.DIRECT, MyBufferType.HEAP, 4096},
+ {false, MyBufferType.DIRECT, MyBufferType.HEAP, 4096},
+ {true, MyBufferType.HEAP, MyBufferType.HEAP, 4096},
+ {false, MyBufferType.HEAP, MyBufferType.HEAP, 4096},
+ {true, MyBufferType.MAPPED, MyBufferType.HEAP, 4096},
+ {false, MyBufferType.MAPPED, MyBufferType.HEAP, 4096},
+ {true, MyBufferType.DIRECT, MyBufferType.MAPPED, 4096},
+ {false, MyBufferType.DIRECT, MyBufferType.MAPPED, 4096},
+ {true, MyBufferType.HEAP, MyBufferType.MAPPED, 4096},
+ {false, MyBufferType.HEAP, MyBufferType.MAPPED, 4096},
+ {true, MyBufferType.MAPPED, MyBufferType.MAPPED, 4096},
+ {false, MyBufferType.MAPPED, MyBufferType.MAPPED, 4096},
+ {true, MyBufferType.DIRECT, MyBufferType.DIRECT, 1232896},
+ {false, MyBufferType.DIRECT, MyBufferType.DIRECT, 1232896},
+ {true, MyBufferType.HEAP, MyBufferType.DIRECT, 1232896},
+ {false, MyBufferType.HEAP, MyBufferType.DIRECT, 1232896},
+ {true, MyBufferType.MAPPED, MyBufferType.DIRECT, 1232896},
+ {false, MyBufferType.MAPPED, MyBufferType.DIRECT, 1232896},
+ {true, MyBufferType.DIRECT, MyBufferType.HEAP, 1232896},
+ {false, MyBufferType.DIRECT, MyBufferType.HEAP, 1232896},
+ {true, MyBufferType.HEAP, MyBufferType.HEAP, 1232896},
+ {false, MyBufferType.HEAP, MyBufferType.HEAP, 1232896},
+ {true, MyBufferType.MAPPED, MyBufferType.HEAP, 1232896},
+ {false, MyBufferType.MAPPED, MyBufferType.HEAP, 1232896},
+ {true, MyBufferType.DIRECT, MyBufferType.MAPPED, 1232896},
+ {false, MyBufferType.DIRECT, MyBufferType.MAPPED, 1232896},
+ {true, MyBufferType.HEAP, MyBufferType.MAPPED, 1232896},
+ {false, MyBufferType.HEAP, MyBufferType.MAPPED, 1232896},
+ {true, MyBufferType.MAPPED, MyBufferType.MAPPED, 1232896},
+ {false, MyBufferType.MAPPED, MyBufferType.MAPPED, 1232896},
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public boolean mAligned;
+
+ enum MyBufferType {
+ DIRECT,
+ HEAP,
+ MAPPED
+ }
+
+ @Parameterized.Parameter(1)
+ public MyBufferType mSrcBufferType;
+
+ @Parameterized.Parameter(2)
+ public MyBufferType mDataBufferType;
+
+ @Parameterized.Parameter(3)
+ public int mBufferSize;
+
+ public static ByteBuffer newBuffer(boolean aligned, MyBufferType bufferType, int bsize)
+ throws IOException {
+ int size = aligned ? bsize : bsize + 8 + 1;
+ ByteBuffer result = null;
+ switch (bufferType) {
+ case DIRECT:
+ result = ByteBuffer.allocateDirect(size);
+ break;
+ case HEAP:
+ result = ByteBuffer.allocate(size);
+ break;
+ case MAPPED:
+ File tmpFile = File.createTempFile("MappedByteBufferTest", ".tmp");
+ tmpFile.createNewFile();
+ tmpFile.deleteOnExit();
+ RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
+ raf.setLength(size);
+ FileChannel fc = raf.getChannel();
+ result = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
+ break;
+ }
+ result.position(aligned ? 0 : 1);
+ return result;
+ }
+
+ @Test
+ public void timeByteBuffer_putByteBuffer() throws Exception {
+ ByteBuffer src = ByteBufferBulkPerfTest.newBuffer(mAligned, mSrcBufferType, mBufferSize);
+ ByteBuffer data = ByteBufferBulkPerfTest.newBuffer(mAligned, mDataBufferType, mBufferSize);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ data.position(mAligned ? 0 : 1);
+ src.put(data);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferPerfTest.java
new file mode 100644
index 0000000..4bd7c4e
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferPerfTest.java
@@ -0,0 +1,532 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.ShortBuffer;
+import java.nio.channels.FileChannel;
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class ByteBufferPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ public enum MyByteOrder {
+ BIG(ByteOrder.BIG_ENDIAN),
+ LITTLE(ByteOrder.LITTLE_ENDIAN);
+ final ByteOrder mByteOrder;
+
+ MyByteOrder(ByteOrder mByteOrder) {
+ this.mByteOrder = mByteOrder;
+ }
+ }
+
+ @Parameters(name = "mByteOrder={0}, mAligned={1}, mBufferType={2}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {MyByteOrder.BIG, true, MyBufferType.DIRECT},
+ {MyByteOrder.LITTLE, true, MyBufferType.DIRECT},
+ {MyByteOrder.BIG, false, MyBufferType.DIRECT},
+ {MyByteOrder.LITTLE, false, MyBufferType.DIRECT},
+ {MyByteOrder.BIG, true, MyBufferType.HEAP},
+ {MyByteOrder.LITTLE, true, MyBufferType.HEAP},
+ {MyByteOrder.BIG, false, MyBufferType.HEAP},
+ {MyByteOrder.LITTLE, false, MyBufferType.HEAP},
+ {MyByteOrder.BIG, true, MyBufferType.MAPPED},
+ {MyByteOrder.LITTLE, true, MyBufferType.MAPPED},
+ {MyByteOrder.BIG, false, MyBufferType.MAPPED},
+ {MyByteOrder.LITTLE, false, MyBufferType.MAPPED}
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public MyByteOrder mByteOrder;
+
+ @Parameterized.Parameter(1)
+ public boolean mAligned;
+
+ enum MyBufferType {
+ DIRECT,
+ HEAP,
+ MAPPED;
+ }
+
+ @Parameterized.Parameter(2)
+ public MyBufferType mBufferType;
+
+ public static ByteBuffer newBuffer(
+ MyByteOrder byteOrder, boolean aligned, MyBufferType bufferType) throws IOException {
+ int size = aligned ? 8192 : 8192 + 8 + 1;
+ ByteBuffer result = null;
+ switch (bufferType) {
+ case DIRECT:
+ result = ByteBuffer.allocateDirect(size);
+ break;
+ case HEAP:
+ result = ByteBuffer.allocate(size);
+ break;
+ case MAPPED:
+ File tmpFile = new File("/sdcard/bm.tmp");
+ if (new File("/tmp").isDirectory()) {
+ // We're running on the desktop.
+ tmpFile = File.createTempFile("MappedByteBufferTest", ".tmp");
+ }
+ tmpFile.createNewFile();
+ tmpFile.deleteOnExit();
+ RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
+ raf.setLength(8192 * 8);
+ FileChannel fc = raf.getChannel();
+ result = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
+ break;
+ }
+ result.order(byteOrder.mByteOrder);
+ result.position(aligned ? 0 : 1);
+ return result;
+ }
+
+ //
+ // peeking
+ //
+
+ @Test
+ public void timeByteBuffer_getByte() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.get();
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getByteArray() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ byte[] dst = new byte[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(mAligned ? 0 : 1);
+ src.get(dst);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getByte_indexed() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.get(i);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getChar() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getChar();
+ }
+ }
+ }
+
+ @Test
+ public void timeCharBuffer_getCharArray() throws Exception {
+ CharBuffer src =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asCharBuffer();
+ char[] dst = new char[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(0);
+ src.get(dst);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getChar_indexed() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getChar(i * 2);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getDouble() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getDouble();
+ }
+ }
+ }
+
+ @Test
+ public void timeDoubleBuffer_getDoubleArray() throws Exception {
+ DoubleBuffer src =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asDoubleBuffer();
+ double[] dst = new double[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(0);
+ src.get(dst);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getFloat() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getFloat();
+ }
+ }
+ }
+
+ @Test
+ public void timeFloatBuffer_getFloatArray() throws Exception {
+ FloatBuffer src =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asFloatBuffer();
+ float[] dst = new float[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(0);
+ src.get(dst);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getInt() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getInt();
+ }
+ }
+ }
+
+ @Test
+ public void timeIntBuffer_getIntArray() throws Exception {
+ IntBuffer src =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asIntBuffer();
+ int[] dst = new int[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(0);
+ src.get(dst);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getLong() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getLong();
+ }
+ }
+ }
+
+ @Test
+ public void timeLongBuffer_getLongArray() throws Exception {
+ LongBuffer src =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asLongBuffer();
+ long[] dst = new long[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(0);
+ src.get(dst);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_getShort() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.getShort();
+ }
+ }
+ }
+
+ @Test
+ public void timeShortBuffer_getShortArray() throws Exception {
+ ShortBuffer src =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asShortBuffer();
+ short[] dst = new short[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ src.position(0);
+ src.get(dst);
+ }
+ }
+ }
+
+ //
+ // poking
+ //
+
+ @Test
+ public void timeByteBuffer_putByte() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(0);
+ for (int i = 0; i < 1024; ++i) {
+ src.put((byte) 0);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putByteArray() throws Exception {
+ ByteBuffer dst = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ byte[] src = new byte[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(mAligned ? 0 : 1);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putChar() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.putChar(' ');
+ }
+ }
+ }
+
+ @Test
+ public void timeCharBuffer_putCharArray() throws Exception {
+ CharBuffer dst =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asCharBuffer();
+ char[] src = new char[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(0);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putDouble() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.putDouble(0.0);
+ }
+ }
+ }
+
+ @Test
+ public void timeDoubleBuffer_putDoubleArray() throws Exception {
+ DoubleBuffer dst =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asDoubleBuffer();
+ double[] src = new double[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(0);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putFloat() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.putFloat(0.0f);
+ }
+ }
+ }
+
+ @Test
+ public void timeFloatBuffer_putFloatArray() throws Exception {
+ FloatBuffer dst =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asFloatBuffer();
+ float[] src = new float[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(0);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putInt() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.putInt(0);
+ }
+ }
+ }
+
+ @Test
+ public void timeIntBuffer_putIntArray() throws Exception {
+ IntBuffer dst =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asIntBuffer();
+ int[] src = new int[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(0);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putLong() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.putLong(0L);
+ }
+ }
+ }
+
+ @Test
+ public void timeLongBuffer_putLongArray() throws Exception {
+ LongBuffer dst =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asLongBuffer();
+ long[] src = new long[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(0);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBuffer_putShort() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ for (int i = 0; i < 1024; ++i) {
+ src.putShort((short) 0);
+ }
+ }
+ }
+
+ @Test
+ public void timeShortBuffer_putShortArray() throws Exception {
+ ShortBuffer dst =
+ ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType).asShortBuffer();
+ short[] src = new short[1024];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < 1024; ++i) {
+ dst.position(0);
+ dst.put(src);
+ }
+ }
+ }
+
+ @Test
+ public void time_new_byteArray() throws Exception {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ byte[] bs = new byte[8192];
+ }
+ }
+
+ @Test
+ public void time_ByteBuffer_allocate() throws Exception {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ ByteBuffer bs = ByteBuffer.allocate(8192);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferScalarVersusVectorPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferScalarVersusVectorPerfTest.java
new file mode 100644
index 0000000..81f9e59
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/ByteBufferScalarVersusVectorPerfTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class ByteBufferScalarVersusVectorPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "mByteOrder={0}, mAligned={1}, mBufferType={2}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {
+ ByteBufferPerfTest.MyByteOrder.BIG,
+ true,
+ ByteBufferPerfTest.MyBufferType.DIRECT
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.LITTLE,
+ true,
+ ByteBufferPerfTest.MyBufferType.DIRECT
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.BIG,
+ false,
+ ByteBufferPerfTest.MyBufferType.DIRECT
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.LITTLE,
+ false,
+ ByteBufferPerfTest.MyBufferType.DIRECT
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.BIG,
+ true,
+ ByteBufferPerfTest.MyBufferType.HEAP
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.LITTLE,
+ true,
+ ByteBufferPerfTest.MyBufferType.HEAP
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.BIG,
+ false,
+ ByteBufferPerfTest.MyBufferType.HEAP
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.LITTLE,
+ false,
+ ByteBufferPerfTest.MyBufferType.HEAP
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.BIG,
+ true,
+ ByteBufferPerfTest.MyBufferType.MAPPED
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.LITTLE,
+ true,
+ ByteBufferPerfTest.MyBufferType.MAPPED
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.BIG,
+ false,
+ ByteBufferPerfTest.MyBufferType.MAPPED
+ },
+ {
+ ByteBufferPerfTest.MyByteOrder.LITTLE,
+ false,
+ ByteBufferPerfTest.MyBufferType.MAPPED
+ }
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public ByteBufferPerfTest.MyByteOrder mByteOrder;
+
+ @Parameterized.Parameter(1)
+ public boolean mAligned;
+
+ @Parameterized.Parameter(2)
+ public ByteBufferPerfTest.MyBufferType mBufferType;
+
+ @Test
+ public void timeManualByteBufferCopy() throws Exception {
+ ByteBuffer src = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ ByteBuffer dst = ByteBufferPerfTest.newBuffer(mByteOrder, mAligned, mBufferType);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(0);
+ dst.position(0);
+ for (int i = 0; i < 8192; ++i) {
+ dst.put(src.get());
+ }
+ }
+ }
+
+ @Test
+ public void timeByteBufferBulkGet() throws Exception {
+ ByteBuffer src = ByteBuffer.allocate(mAligned ? 8192 : 8192 + 1);
+ byte[] dst = new byte[8192];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ src.get(dst, 0, dst.length);
+ }
+ }
+
+ @Test
+ public void timeDirectByteBufferBulkGet() throws Exception {
+ ByteBuffer src = ByteBuffer.allocateDirect(mAligned ? 8192 : 8192 + 1);
+ byte[] dst = new byte[8192];
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ src.position(mAligned ? 0 : 1);
+ src.get(dst, 0, dst.length);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CharacterPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CharacterPerfTest.java
new file mode 100644
index 0000000..28ec6de
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CharacterPerfTest.java
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ * Tests various Character methods, intended for testing multiple implementations against each
+ * other.
+ */
+@RunWith(Parameterized.class)
+@LargeTest
+public class CharacterPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "mCharacterSet({0}), mOverload({1})")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {CharacterSet.ASCII, Overload.CHAR},
+ {CharacterSet.ASCII, Overload.INT},
+ {CharacterSet.UNICODE, Overload.CHAR},
+ {CharacterSet.UNICODE, Overload.INT}
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public CharacterSet mCharacterSet;
+
+ @Parameterized.Parameter(1)
+ public Overload mOverload;
+
+ private char[] mChars;
+
+ @Before
+ public void setUp() throws Exception {
+ this.mChars = mCharacterSet.mChars;
+ }
+
+ public enum Overload {
+ CHAR,
+ INT
+ }
+
+ public double nanosToUnits(double nanos) {
+ return nanos / 65536;
+ }
+
+ public enum CharacterSet {
+ ASCII(128),
+ UNICODE(65536);
+ final char[] mChars;
+
+ CharacterSet(int size) {
+ this.mChars = new char[65536];
+ for (int i = 0; i < 65536; ++i) {
+ mChars[i] = (char) (i % size);
+ }
+ }
+ }
+
+ // A fake benchmark to give us a baseline.
+ @Test
+ public void timeIsSpace() {
+ boolean fake = false;
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ fake ^= ((char) ch == ' ');
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ fake ^= (ch == ' ');
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeDigit() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.digit(mChars[ch], 10);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.digit((int) mChars[ch], 10);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeGetNumericValue() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.getNumericValue(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.getNumericValue((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsDigit() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isDigit(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isDigit((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsIdentifierIgnorable() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isIdentifierIgnorable(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isIdentifierIgnorable((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsJavaIdentifierPart() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isJavaIdentifierPart(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isJavaIdentifierPart((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsJavaIdentifierStart() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isJavaIdentifierStart(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isJavaIdentifierStart((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsLetter() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isLetter(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isLetter((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsLetterOrDigit() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isLetterOrDigit(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isLetterOrDigit((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsLowerCase() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isLowerCase(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isLowerCase((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsSpaceChar() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isSpaceChar(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isSpaceChar((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsUpperCase() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isUpperCase(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isUpperCase((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeIsWhitespace() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isWhitespace(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.isWhitespace((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeToLowerCase() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.toLowerCase(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.toLowerCase((int) mChars[ch]);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void timeToUpperCase() {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ if (mOverload == Overload.CHAR) {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.toUpperCase(mChars[ch]);
+ }
+ }
+ } else {
+ while (state.keepRunning()) {
+ for (int ch = 0; ch < 65536; ++ch) {
+ Character.toUpperCase((int) mChars[ch]);
+ }
+ }
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CharsetForNamePerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CharsetForNamePerfTest.java
new file mode 100644
index 0000000..603b182
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CharsetForNamePerfTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class CharsetForNamePerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameterized.Parameters(name = "mCharsetName({0})")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {"UTF-16"},
+ {"UTF-8"},
+ {"UTF8"},
+ {"ISO-8859-1"},
+ {"8859_1"},
+ {"ISO-8859-2"},
+ {"8859_2"},
+ {"US-ASCII"},
+ {"ASCII"},
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public String mCharsetName;
+
+ @Test
+ public void timeCharsetForName() throws Exception {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Charset.forName(mCharsetName);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CharsetPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CharsetPerfTest.java
new file mode 100644
index 0000000..437d186
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CharsetPerfTest.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class CharsetPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "mLength({0}), mName({1})")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(
+ new Object[][] {
+ {1, "UTF-16"},
+ {1, "UTF-8"},
+ {1, "UTF8"},
+ {1, "ISO-8859-1"},
+ {1, "8859_1"},
+ {1, "ISO-8859-2"},
+ {1, "8859_2"},
+ {1, "US-ASCII"},
+ {1, "ASCII"},
+ {10, "UTF-16"},
+ {10, "UTF-8"},
+ {10, "UTF8"},
+ {10, "ISO-8859-1"},
+ {10, "8859_1"},
+ {10, "ISO-8859-2"},
+ {10, "8859_2"},
+ {10, "US-ASCII"},
+ {10, "ASCII"},
+ {100, "UTF-16"},
+ {100, "UTF-8"},
+ {100, "UTF8"},
+ {100, "ISO-8859-1"},
+ {100, "8859_1"},
+ {100, "ISO-8859-2"},
+ {100, "8859_2"},
+ {100, "US-ASCII"},
+ {100, "ASCII"},
+ {1000, "UTF-16"},
+ {1000, "UTF-8"},
+ {1000, "UTF8"},
+ {1000, "ISO-8859-1"},
+ {1000, "8859_1"},
+ {1000, "ISO-8859-2"},
+ {1000, "8859_2"},
+ {1000, "US-ASCII"},
+ {1000, "ASCII"},
+ {10000, "UTF-16"},
+ {10000, "UTF-8"},
+ {10000, "UTF8"},
+ {10000, "ISO-8859-1"},
+ {10000, "8859_1"},
+ {10000, "ISO-8859-2"},
+ {10000, "8859_2"},
+ {10000, "US-ASCII"},
+ {10000, "ASCII"},
+ });
+ }
+
+ @Parameterized.Parameter(0)
+ public int mLength;
+
+ @Parameterized.Parameter(1)
+ public String mName;
+
+ @Test
+ public void time_new_String_BString() throws Exception {
+ byte[] bytes = makeBytes(makeString(mLength));
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ new String(bytes, mName);
+ }
+ }
+
+ @Test
+ public void time_new_String_BII() throws Exception {
+ byte[] bytes = makeBytes(makeString(mLength));
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ new String(bytes, 0, bytes.length);
+ }
+ }
+
+ @Test
+ public void time_new_String_BIIString() throws Exception {
+ byte[] bytes = makeBytes(makeString(mLength));
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ new String(bytes, 0, bytes.length, mName);
+ }
+ }
+
+ @Test
+ public void time_String_getBytes() throws Exception {
+ String string = makeString(mLength);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ string.getBytes(mName);
+ }
+ }
+
+ private static String makeString(int length) {
+ StringBuilder result = new StringBuilder(length);
+ for (int i = 0; i < length; ++i) {
+ result.append('A' + (i % 26));
+ }
+ return result.toString();
+ }
+
+ private static byte[] makeBytes(String s) {
+ try {
+ return s.getBytes("US-ASCII");
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CharsetUtf8PerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CharsetUtf8PerfTest.java
new file mode 100644
index 0000000..f31e9c1
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CharsetUtf8PerfTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2017 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 android.libcore.regression;
+
+import android.icu.lang.UCharacter;
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.nio.charset.Charset;
+
+/**
+ * Decode the same size of ASCII, BMP, Supplementary character using fast-path UTF-8 decoder. The
+ * fast-path code is in {@link StringFactory#newStringFromBytes(byte[], int, int, Charset)}
+ */
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class CharsetUtf8PerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private final int mNoOfBytes = 0x100; // 4MB
+
+ private void makeUnicodeRange(int startingCodePoint, int endingCodePoint, int repeated) {
+ StringBuilder builder = new StringBuilder();
+ for (int codePoint = startingCodePoint; codePoint <= endingCodePoint; codePoint++) {
+ if (codePoint < Character.MIN_SURROGATE || codePoint > Character.MAX_SURROGATE) {
+ builder.append(UCharacter.toString(codePoint));
+ }
+ }
+
+ String str = builder.toString();
+ StringBuilder builder2 = new StringBuilder();
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ for (int i = 0; i < repeated; i++) {
+ builder2.append(str);
+ }
+ }
+ }
+
+ @Test
+ public void time_ascii() {
+ makeUnicodeRange(0, 0x7f, mNoOfBytes / 0x80);
+ }
+
+ @Test
+ public void time_bmp2() {
+ makeUnicodeRange(0x0080, 0x07ff, mNoOfBytes / 2 / 0x780);
+ }
+
+ @Test
+ public void time_bmp3() {
+ makeUnicodeRange(
+ 0x0800,
+ 0xffff,
+ mNoOfBytes / 3 / 0xf000 /* 0x10000 - 0x0800 - no of surrogate code points */);
+ }
+
+ @Test
+ public void time_supplementary() {
+ makeUnicodeRange(0x10000, 0x10ffff, mNoOfBytes / 4 / 0x100000);
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/ChecksumPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/ChecksumPerfTest.java
new file mode 100644
index 0000000..1d33fcb
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/ChecksumPerfTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.zip.Adler32;
+import java.util.zip.CRC32;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class ChecksumPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Test
+ public void timeAdler_block() throws Exception {
+ byte[] bytes = new byte[10000];
+ Adler32 adler = new Adler32();
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ adler.update(bytes);
+ }
+ }
+
+ @Test
+ public void timeAdler_byte() throws Exception {
+ Adler32 adler = new Adler32();
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ adler.update(1);
+ }
+ }
+
+ @Test
+ public void timeCrc_block() throws Exception {
+ byte[] bytes = new byte[10000];
+ CRC32 crc = new CRC32();
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ crc.update(bytes);
+ }
+ }
+
+ @Test
+ public void timeCrc_byte() throws Exception {
+ CRC32 crc = new CRC32();
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ crc.update(1);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CipherInputStreamPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CipherInputStreamPerfTest.java
new file mode 100644
index 0000000..35730ec
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CipherInputStreamPerfTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
+
+/** CipherInputStream benchmark. */
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class CipherInputStreamPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private static final int DATA_SIZE = 1024 * 1024;
+ private static final byte[] DATA = new byte[DATA_SIZE];
+
+ private static final int IV_SIZE = 16;
+ private static final byte[] IV = new byte[IV_SIZE];
+
+ static {
+ for (int i = 0; i < DATA_SIZE; i++) {
+ DATA[i] = (byte) i;
+ }
+ for (int i = 0; i < IV_SIZE; i++) {
+ IV[i] = (byte) i;
+ }
+ }
+
+ private SecretKey mKey;
+
+ private byte[] mOutput = new byte[8192];
+
+ private Cipher mCipherEncrypt;
+
+ private AlgorithmParameterSpec mSpec;
+
+ @Before
+ public void setUp() throws Exception {
+ KeyGenerator generator = KeyGenerator.getInstance("AES");
+ generator.init(128);
+ mKey = generator.generateKey();
+
+ mSpec = new IvParameterSpec(IV);
+
+ mCipherEncrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
+ mCipherEncrypt.init(Cipher.ENCRYPT_MODE, mKey, mSpec);
+ }
+
+ @Test
+ public void timeEncrypt() throws Exception {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mCipherEncrypt.init(Cipher.ENCRYPT_MODE, mKey, mSpec);
+ InputStream is = new CipherInputStream(new ByteArrayInputStream(DATA), mCipherEncrypt);
+ while (is.read(mOutput) != -1) {
+ // Keep iterating
+ }
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CipherPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CipherPerfTest.java
new file mode 100644
index 0000000..15c27f2
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CipherPerfTest.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.security.spec.AlgorithmParameterSpec;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
+
+/**
+ * Cipher benchmarks. Only runs on AES currently because of the combinatorial explosion of the test
+ * as it stands.
+ */
+@RunWith(Parameterized.class)
+@LargeTest
+public class CipherPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameterized.Parameters(
+ name =
+ "mMode({0}), mPadding({1}), mKeySize({2}), mInputSize({3}),"
+ + " mImplementation({4})")
+ public static Collection cases() {
+ int[] mKeySizes = new int[] {128, 192, 256};
+ int[] inputSizes = new int[] {16, 32, 64, 128, 1024, 8192};
+ final List<Object[]> params = new ArrayList<>();
+ for (Mode mode : Mode.values()) {
+ for (Padding padding : Padding.values()) {
+ for (Implementation implementation : Implementation.values()) {
+ if ((mode == Mode.CBC
+ || mode == Mode.CFB
+ || mode == Mode.CTR
+ || mode == Mode.ECB
+ || mode == Mode.OFB)
+ && padding == Padding.PKCS1PADDING) {
+ continue;
+ }
+ if ((mode == Mode.CFB || mode == Mode.OFB)
+ && padding == Padding.NOPADDING
+ && implementation == Implementation.OpenSSL) {
+ continue;
+ }
+ for (int mKeySize : mKeySizes) {
+ for (int inputSize : inputSizes) {
+ params.add(
+ new Object[] {
+ mode, padding, mKeySize, inputSize, implementation
+ });
+ }
+ }
+ }
+ }
+ }
+ return params;
+ }
+
+ private static final int DATA_SIZE = 8192;
+ private static final byte[] DATA = new byte[DATA_SIZE];
+
+ private static final int IV_SIZE = 16;
+
+ private static final byte[] IV = new byte[IV_SIZE];
+
+ static {
+ for (int i = 0; i < DATA_SIZE; i++) {
+ DATA[i] = (byte) i;
+ }
+ for (int i = 0; i < IV_SIZE; i++) {
+ IV[i] = (byte) i;
+ }
+ }
+
+ public Algorithm mAlgorithm = Algorithm.AES;
+
+ public enum Algorithm {
+ AES,
+ };
+
+ @Parameterized.Parameter(0)
+ public Mode mMode;
+
+ public enum Mode {
+ CBC,
+ CFB,
+ CTR,
+ ECB,
+ OFB,
+ };
+
+ @Parameterized.Parameter(1)
+ public Padding mPadding;
+
+ public enum Padding {
+ NOPADDING,
+ PKCS1PADDING,
+ };
+
+ @Parameterized.Parameter(2)
+ public int mKeySize;
+
+ @Parameterized.Parameter(3)
+ public int mInputSize;
+
+ @Parameterized.Parameter(4)
+ public Implementation mImplementation;
+
+ public enum Implementation {
+ OpenSSL,
+ BouncyCastle
+ };
+
+ private String mProviderName;
+
+ // Key generation isn't part of the benchmark so cache the results
+ private static Map<Integer, SecretKey> sKeySizes = new HashMap<Integer, SecretKey>();
+
+ private String mCipherAlgorithm;
+ private SecretKey mKey;
+
+ private byte[] mOutput = new byte[DATA.length];
+
+ private Cipher mCipherEncrypt;
+
+ private Cipher mCipherDecrypt;
+
+ private AlgorithmParameterSpec mSpec;
+
+ @Before
+ public void setUp() throws Exception {
+ mCipherAlgorithm =
+ mAlgorithm.toString() + "/" + mMode.toString() + "/" + mPadding.toString();
+
+ String mKeyAlgorithm = mAlgorithm.toString();
+ mKey = sKeySizes.get(mKeySize);
+ if (mKey == null) {
+ KeyGenerator generator = KeyGenerator.getInstance(mKeyAlgorithm);
+ generator.init(mKeySize);
+ mKey = generator.generateKey();
+ sKeySizes.put(mKeySize, mKey);
+ }
+
+ switch (mImplementation) {
+ case OpenSSL:
+ mProviderName = "AndroidOpenSSL";
+ break;
+ case BouncyCastle:
+ mProviderName = "BC";
+ break;
+ default:
+ throw new RuntimeException(mImplementation.toString());
+ }
+
+ if (mMode != Mode.ECB) {
+ mSpec = new IvParameterSpec(IV);
+ }
+
+ mCipherEncrypt = Cipher.getInstance(mCipherAlgorithm, mProviderName);
+ mCipherEncrypt.init(Cipher.ENCRYPT_MODE, mKey, mSpec);
+
+ mCipherDecrypt = Cipher.getInstance(mCipherAlgorithm, mProviderName);
+ mCipherDecrypt.init(Cipher.DECRYPT_MODE, mKey, mSpec);
+ }
+
+ @Test
+ public void timeEncrypt() throws Exception {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mCipherEncrypt.doFinal(DATA, 0, mInputSize, mOutput);
+ }
+ }
+
+ @Test
+ public void timeDecrypt() throws Exception {
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mCipherDecrypt.doFinal(DATA, 0, mInputSize, mOutput);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CollatorPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CollatorPerfTest.java
new file mode 100644
index 0000000..6728e73
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CollatorPerfTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2022 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.text.Collator;
+import java.text.RuleBasedCollator;
+import java.util.Locale;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class CollatorPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private static final RuleBasedCollator COLLATOR =
+ (RuleBasedCollator) Collator.getInstance(Locale.US);
+
+ @Test
+ public void timeCollatorPrimary() {
+ COLLATOR.setStrength(Collator.PRIMARY);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ COLLATOR.compare("abcde", "abcdf");
+ COLLATOR.compare("abcde", "abcde");
+ COLLATOR.compare("abcdf", "abcde");
+ }
+ }
+
+ @Test
+ public void timeCollatorSecondary() {
+ COLLATOR.setStrength(Collator.SECONDARY);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ COLLATOR.compare("abcdÂ", "abcdÄ");
+ COLLATOR.compare("abcdÂ", "abcdÂ");
+ COLLATOR.compare("abcdÄ", "abcdÂ");
+ }
+ }
+
+ @Test
+ public void timeCollatorTertiary() {
+ COLLATOR.setStrength(Collator.TERTIARY);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ COLLATOR.compare("abcdE", "abcde");
+ COLLATOR.compare("abcde", "abcde");
+ COLLATOR.compare("abcde", "abcdE");
+ }
+ }
+
+ @Test
+ public void timeCollatorIdentical() {
+ COLLATOR.setStrength(Collator.IDENTICAL);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ COLLATOR.compare("abcdȪ", "abcdȫ");
+ COLLATOR.compare("abcdȪ", "abcdȪ");
+ COLLATOR.compare("abcdȫ", "abcdȪ");
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/libcore/regression/CollectionsPerfTest.java b/apct-tests/perftests/core/src/android/libcore/regression/CollectionsPerfTest.java
new file mode 100644
index 0000000..a89efff
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/libcore/regression/CollectionsPerfTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2014 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 android.libcore.regression;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.test.suitebuilder.annotation.LargeTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Random;
+import java.util.Vector;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class CollectionsPerfTest {
+ @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "mArrayListLength({0})")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{4}, {16}, {64}, {256}, {1024}});
+ }
+
+ @Parameterized.Parameter(0)
+ public int arrayListLength;
+
+ public static Comparator<Integer> REVERSE =
+ new Comparator<Integer>() {
+ @Override
+ public int compare(Integer lhs, Integer rhs) {
+ int lhsAsInt = lhs.intValue();
+ int rhsAsInt = rhs.intValue();
+ return rhsAsInt < lhsAsInt ? -1 : (lhsAsInt == rhsAsInt ? 0 : 1);
+ }
+ };
+
+ @Test
+ public void timeSort_arrayList() throws Exception {
+ List<Integer> input = buildList(arrayListLength, ArrayList.class);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Collections.sort(input);
+ }
+ }
+
+ @Test
+ public void timeSortWithComparator_arrayList() throws Exception {
+ List<Integer> input = buildList(arrayListLength, ArrayList.class);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Collections.sort(input, REVERSE);
+ }
+ }
+
+ @Test
+ public void timeSort_vector() throws Exception {
+ List<Integer> input = buildList(arrayListLength, Vector.class);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Collections.sort(input);
+ }
+ }
+
+ @Test
+ public void timeSortWithComparator_vector() throws Exception {
+ List<Integer> input = buildList(arrayListLength, Vector.class);
+ BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ Collections.sort(input, REVERSE);
+ }
+ }
+
+ private static <T extends List<Integer>> List<Integer> buildList(
+ int arrayListLength, Class<T> listClass) throws Exception {
+ Random random = new Random();
+ random.setSeed(0);
+ List<Integer> list = listClass.newInstance();
+ for (int i = 0; i < arrayListLength; ++i) {
+ list.add(random.nextInt());
+ }
+ return list;
+ }
+}