Debian Codegraph @

core/tests/benchmarks/src/android/os/ParcelStringBenchmark.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.os;
18
19 import com.google.caliper.AfterExperiment;
20 import com.google.caliper.BeforeExperiment;
21 import com.google.caliper.Param;
22
23 public class ParcelStringBenchmark {
24
25 @Param({"com.example.typical_package_name", "從不喜歡孤單一個 - 蘇永康/吳雨霏"})
26 String mValue;
27
28 private Parcel mParcel;
29
30 @BeforeExperiment
31 protected void setUp() {
32 mParcel = Parcel.obtain();
33 }
34
35 @AfterExperiment
36 protected void tearDown() {
37 mParcel.recycle();
38 mParcel = null;
39 }
40
41 public void timeWriteString8(int reps) {
42 for (int i = 0; i < reps; i++) {
43 mParcel.setDataPosition(0);
44 mParcel.writeString8(mValue);
45 }
46 }
47
48 public void timeReadString8(int reps) {
49 mParcel.writeString8(mValue);
50
51 for (int i = 0; i < reps; i++) {
52 mParcel.setDataPosition(0);
53 mParcel.readString8();
54 }
55 }
56
57 public void timeWriteString16(int reps) {
58 for (int i = 0; i < reps; i++) {
59 mParcel.setDataPosition(0);
60 mParcel.writeString16(mValue);
61 }
62 }
63
64 public void timeReadString16(int reps) {
65 mParcel.writeString16(mValue);
66
67 for (int i = 0; i < reps; i++) {
68 mParcel.setDataPosition(0);
69 mParcel.readString16();
70 }
71 }
72 }