diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-03-07 12:07:01 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-07 12:07:01 -0800 |
commit | 8f409bcd4b14de860e44e4740f8bd212e34cda06 (patch) | |
tree | 187567accb79cb3aeb0d9c37f7070d45bc7867e2 /core/tests | |
parent | e8bacb4ea0bb6b3ec3d3ff5488f3eb1c768b5f90 (diff) | |
parent | a197e37f7fc056f9d6db3ef24b5e6db9222e7b56 (diff) | |
download | frameworks_base-8f409bcd4b14de860e44e4740f8bd212e34cda06.zip frameworks_base-8f409bcd4b14de860e44e4740f8bd212e34cda06.tar.gz frameworks_base-8f409bcd4b14de860e44e4740f8bd212e34cda06.tar.bz2 |
Merge "Caliper benchmarks for Parcel."
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/benchmarks/README | 8 | ||||
-rw-r--r-- | core/tests/benchmarks/src/android/os/ParcelArrayBenchmark.java | 122 | ||||
-rw-r--r-- | core/tests/benchmarks/src/android/os/ParcelBenchmark.java | 77 |
3 files changed, 207 insertions, 0 deletions
diff --git a/core/tests/benchmarks/README b/core/tests/benchmarks/README new file mode 100644 index 0000000..0a41bcc --- /dev/null +++ b/core/tests/benchmarks/README @@ -0,0 +1,8 @@ + +These benchmarks use the Caliper benchmark framework, and can be +run on a remote device using Vogar: + +http://code.google.com/p/caliper/ +http://code.google.com/p/vogar/ + +$ vogar --benchmark path/to/Benchmark.java diff --git a/core/tests/benchmarks/src/android/os/ParcelArrayBenchmark.java b/core/tests/benchmarks/src/android/os/ParcelArrayBenchmark.java new file mode 100644 index 0000000..21cfb09 --- /dev/null +++ b/core/tests/benchmarks/src/android/os/ParcelArrayBenchmark.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2012 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 com.google.caliper.Param; +import com.google.caliper.SimpleBenchmark; + +public class ParcelArrayBenchmark extends SimpleBenchmark { + + @Param({ "1", "10", "100", "1000" }) + private int mSize; + + private Parcel mWriteParcel; + + private byte[] mByteArray; + private int[] mIntArray; + private long[] mLongArray; + + private Parcel mByteParcel; + private Parcel mIntParcel; + private Parcel mLongParcel; + + @Override + protected 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); + } + + @Override + protected void tearDown() { + mWriteParcel.recycle(); + mWriteParcel = null; + } + + public void timeWriteByteArray(int reps) { + for (int i = 0; i < reps; i++) { + mWriteParcel.setDataPosition(0); + mWriteParcel.writeByteArray(mByteArray); + } + } + + public void timeCreateByteArray(int reps) { + for (int i = 0; i < reps; i++) { + mByteParcel.setDataPosition(0); + mByteParcel.createByteArray(); + } + } + + public void timeReadByteArray(int reps) { + for (int i = 0; i < reps; i++) { + mByteParcel.setDataPosition(0); + mByteParcel.readByteArray(mByteArray); + } + } + + public void timeWriteIntArray(int reps) { + for (int i = 0; i < reps; i++) { + mWriteParcel.setDataPosition(0); + mWriteParcel.writeIntArray(mIntArray); + } + } + + public void timeCreateIntArray(int reps) { + for (int i = 0; i < reps; i++) { + mIntParcel.setDataPosition(0); + mIntParcel.createIntArray(); + } + } + + public void timeReadIntArray(int reps) { + for (int i = 0; i < reps; i++) { + mIntParcel.setDataPosition(0); + mIntParcel.readIntArray(mIntArray); + } + } + + public void timeWriteLongArray(int reps) { + for (int i = 0; i < reps; i++) { + mWriteParcel.setDataPosition(0); + mWriteParcel.writeLongArray(mLongArray); + } + } + + public void timeCreateLongArray(int reps) { + for (int i = 0; i < reps; i++) { + mLongParcel.setDataPosition(0); + mLongParcel.createLongArray(); + } + } + + public void timeReadLongArray(int reps) { + for (int i = 0; i < reps; i++) { + mLongParcel.setDataPosition(0); + mLongParcel.readLongArray(mLongArray); + } + } + +} diff --git a/core/tests/benchmarks/src/android/os/ParcelBenchmark.java b/core/tests/benchmarks/src/android/os/ParcelBenchmark.java new file mode 100644 index 0000000..6a7b7c8 --- /dev/null +++ b/core/tests/benchmarks/src/android/os/ParcelBenchmark.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2012 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 com.google.caliper.SimpleBenchmark; + +public class ParcelBenchmark extends SimpleBenchmark { + + private Parcel mParcel; + + @Override + protected void setUp() { + mParcel = Parcel.obtain(); + } + + @Override + protected void tearDown() { + mParcel.recycle(); + mParcel = null; + } + + public void timeWriteByte(int reps) { + final byte val = 0xF; + for (int i = 0; i < reps; i++) { + mParcel.writeByte(val); + } + } + + public void timeReadByte(int reps) { + mParcel.setDataCapacity(reps); + for (int i = 0; i < reps; i++) { + mParcel.readByte(); + } + } + + public void timeWriteInt(int reps) { + final int val = 0xF; + for (int i = 0; i < reps; i++) { + mParcel.writeInt(val); + } + } + + public void timeReadInt(int reps) { + mParcel.setDataCapacity(reps << 2); + for (int i = 0; i < reps; i++) { + mParcel.readInt(); + } + } + + public void timeWriteLong(int reps) { + final long val = 0xF; + for (int i = 0; i < reps; i++) { + mParcel.writeLong(val); + } + } + + public void timeReadLong(int reps) { + mParcel.setDataCapacity(reps << 3); + for (int i = 0; i < reps; i++) { + mParcel.readLong(); + } + } +} |