summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author John Reck <jreck@google.com> 2016-10-17 15:18:26 -0700
committer John Reck <jreck@google.com> 2016-10-17 15:29:17 -0700
commit306928c49d271f55eecac7d7686295d2a12f905c (patch)
tree4ec68bbaf24ac6bf23917b8d84df9fbe305568b2
parentc93a7ef9cbba1afe1c1c24b500c3ebf67d4ef9b1 (diff)
Port Parcel benchmarks to APCT
Test: ran benchmarks Change-Id: I5b4fad7e1183c8634df4f02bd71701b37fdbc3be
-rw-r--r--apct-tests/perftests/core/src/android/os/ParcelArrayPerfTest.java163
-rw-r--r--apct-tests/perftests/core/src/android/os/ParcelPerfTest.java115
2 files changed, 278 insertions, 0 deletions
diff --git a/apct-tests/perftests/core/src/android/os/ParcelArrayPerfTest.java b/apct-tests/perftests/core/src/android/os/ParcelArrayPerfTest.java
new file mode 100644
index 000000000000..a67aeca95540
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/os/ParcelArrayPerfTest.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2016 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.os;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.support.test.filters.LargeTest;
+
+import org.junit.After;
+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;
+
+@RunWith(Parameterized.class)
+@LargeTest
+public class ParcelArrayPerfTest {
+ @Rule
+ public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ @Parameters(name = "size={0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] { {1}, {10}, {100}, {1000} });
+ }
+
+ private final int mSize;
+
+ private Parcel mWriteParcel;
+
+ private byte[] mByteArray;
+ private int[] mIntArray;
+ private long[] mLongArray;
+
+ private Parcel mByteParcel;
+ private Parcel mIntParcel;
+ private Parcel mLongParcel;
+
+ public ParcelArrayPerfTest(int size) {
+ mSize = size;
+ }
+
+ @Before
+ public void setUp() {
+ mWriteParcel = Parcel.obtain();
+
+ mByteArray = new byte[mSize];
+ mIntArray = new int[mSize];
+ mLongArray = new long[mSize];
+
+ mByteParcel = Parcel.obtain();
+ mByteParcel.writeByteArray(mByteArray);
+ mIntParcel = Parcel.obtain();
+ mIntParcel.writeIntArray(mIntArray);
+ mLongParcel = Parcel.obtain();
+ mLongParcel.writeLongArray(mLongArray);
+ }
+
+ @After
+ public void tearDown() {
+ mWriteParcel.recycle();
+ mWriteParcel = null;
+ }
+
+ @Test
+ public void timeWriteByteArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mWriteParcel.setDataPosition(0);
+ mWriteParcel.writeByteArray(mByteArray);
+ }
+ }
+
+ @Test
+ public void timeCreateByteArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mByteParcel.setDataPosition(0);
+ mByteParcel.createByteArray();
+ }
+ }
+
+ @Test
+ public void timeReadByteArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mByteParcel.setDataPosition(0);
+ mByteParcel.readByteArray(mByteArray);
+ }
+ }
+
+ @Test
+ public void timeWriteIntArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mWriteParcel.setDataPosition(0);
+ mWriteParcel.writeIntArray(mIntArray);
+ }
+ }
+
+ @Test
+ public void timeCreateIntArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mIntParcel.setDataPosition(0);
+ mIntParcel.createIntArray();
+ }
+ }
+
+ @Test
+ public void timeReadIntArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mIntParcel.setDataPosition(0);
+ mIntParcel.readIntArray(mIntArray);
+ }
+ }
+
+ @Test
+ public void timeWriteLongArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mWriteParcel.setDataPosition(0);
+ mWriteParcel.writeLongArray(mLongArray);
+ }
+ }
+
+ @Test
+ public void timeCreateLongArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mLongParcel.setDataPosition(0);
+ mLongParcel.createLongArray();
+ }
+ }
+
+ @Test
+ public void timeReadLongArray() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mLongParcel.setDataPosition(0);
+ mLongParcel.readLongArray(mLongArray);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/os/ParcelPerfTest.java b/apct-tests/perftests/core/src/android/os/ParcelPerfTest.java
new file mode 100644
index 000000000000..8cd45f7f92bd
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/os/ParcelPerfTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2016 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.os;
+
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.support.test.filters.LargeTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class ParcelPerfTest {
+ @Rule
+ public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private Parcel mParcel;
+
+ @Before
+ public void setUp() {
+ mParcel = Parcel.obtain();
+ mParcel.setDataPosition(0);
+ mParcel.setDataCapacity(8);
+ }
+
+ @After
+ public void tearDown() {
+ mParcel.recycle();
+ mParcel = null;
+ }
+
+ @Test
+ public void timeSetDataPosition() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ }
+ }
+
+ @Test
+ public void timeWriteByte() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ final byte val = 0xF;
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ mParcel.writeByte(val);
+ }
+ }
+
+ @Test
+ public void timeReadByte() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ mParcel.readByte();
+ }
+ }
+
+ @Test
+ public void timeWriteInt() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ final int val = 0xF;
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ mParcel.writeInt(val);
+ }
+ }
+
+ @Test
+ public void timeReadInt() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ mParcel.readInt();
+ }
+ }
+
+ @Test
+ public void timeWriteLong() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ final long val = 0xF;
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ mParcel.writeLong(val);
+ }
+ }
+
+ @Test
+ public void timeReadLong() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ while (state.keepRunning()) {
+ mParcel.setDataPosition(0);
+ mParcel.readLong();
+ }
+ }
+}