Debian Codegraph @

apct-tests/perftests/core/src/android/os/ParcelArrayPerfTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17 package android.os;
18
19 import android.perftests.utils.BenchmarkState;
20 import android.perftests.utils.PerfStatusReporter;
21
22 import androidx.test.filters.LargeTest;
23
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.Parameterized;
30 import org.junit.runners.Parameterized.Parameters;
31
32 import java.util.Arrays;
33 import java.util.Collection;
34
35 @RunWith(Parameterized.class)
36 @LargeTest
37 public class ParcelArrayPerfTest {
38 @Rule
39 public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
40
41 @Parameters(name = "size={0}")
42 public static Collection<Object[]> data() {
43 return Arrays.asList(new Object[][] { {1}, {10}, {100}, {1000} });
44 }
45
46 private final int mSize;
47
48 private Parcel mWriteParcel;
49
50 private byte[] mByteArray;
51 private int[] mIntArray;
52 private long[] mLongArray;
53
54 private Parcel mByteParcel;
55 private Parcel mIntParcel;
56 private Parcel mLongParcel;
57
58 public ParcelArrayPerfTest(int size) {
59 mSize = size;
60 }
61
62 @Before
63 public void setUp() {
64 mWriteParcel = Parcel.obtain();
65
66 mByteArray = new byte[mSize];
67 mIntArray = new int[mSize];
68 mLongArray = new long[mSize];
69
70 mByteParcel = Parcel.obtain();
71 mByteParcel.writeByteArray(mByteArray);
72 mIntParcel = Parcel.obtain();
73 mIntParcel.writeIntArray(mIntArray);
74 mLongParcel = Parcel.obtain();
75 mLongParcel.writeLongArray(mLongArray);
76 }
77
78 @After
79 public void tearDown() {
80 mWriteParcel.recycle();
81 mWriteParcel = null;
82 }
83
84 @Test
85 public void timeWriteByteArray() {
86 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
87 while (state.keepRunning()) {
88 mWriteParcel.setDataPosition(0);
89 mWriteParcel.writeByteArray(mByteArray);
90 }
91 }
92
93 @Test
94 public void timeCreateByteArray() {
95 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
96 while (state.keepRunning()) {
97 mByteParcel.setDataPosition(0);
98 mByteParcel.createByteArray();
99 }
100 }
101
102 @Test
103 public void timeReadByteArray() {
104 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
105 while (state.keepRunning()) {
106 mByteParcel.setDataPosition(0);
107 mByteParcel.readByteArray(mByteArray);
108 }
109 }
110
111 @Test
112 public void timeWriteIntArray() {
113 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
114 while (state.keepRunning()) {
115 mWriteParcel.setDataPosition(0);
116 mWriteParcel.writeIntArray(mIntArray);
117 }
118 }
119
120 @Test
121 public void timeCreateIntArray() {
122 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
123 while (state.keepRunning()) {
124 mIntParcel.setDataPosition(0);
125 mIntParcel.createIntArray();
126 }
127 }
128
129 @Test
130 public void timeReadIntArray() {
131 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
132 while (state.keepRunning()) {
133 mIntParcel.setDataPosition(0);
134 mIntParcel.readIntArray(mIntArray);
135 }
136 }
137
138 @Test
139 public void timeWriteLongArray() {
140 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
141 while (state.keepRunning()) {
142 mWriteParcel.setDataPosition(0);
143 mWriteParcel.writeLongArray(mLongArray);
144 }
145 }
146
147 @Test
148 public void timeCreateLongArray() {
149 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
150 while (state.keepRunning()) {
151 mLongParcel.setDataPosition(0);
152 mLongParcel.createLongArray();
153 }
154 }
155
156 @Test
157 public void timeReadLongArray() {
158 final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
159 while (state.keepRunning()) {
160 mLongParcel.setDataPosition(0);
161 mLongParcel.readLongArray(mLongArray);
162 }
163 }
164 }