Debian Codegraph @

core/tests/benchmarks/src/android/text/SpannableStringInternalCopyBenchmark.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 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.text;
18
19 import com.google.caliper.AfterExperiment;
20 import com.google.caliper.BeforeExperiment;
21 import com.google.caliper.Benchmark;
22 import com.google.caliper.Param;
23
24 public class SpannableStringInternalCopyBenchmark {
25
26 @Param({"1", "4", "16"})
27 private String paramStringMult;
28
29 private SpannedString spanned;
30
31 @BeforeExperiment
32 protected void setUp() throws Exception {
33 int strSize = Integer.parseInt(paramStringMult);
34 StringBuilder strBuilder = new StringBuilder();
35 for (int i = 0; i < strSize; i++) {
36 strBuilder.append(SpannableStringBuilderBenchmark.TEST_STRING);
37 }
38 Spanned source = Html.fromHtml(strBuilder.toString());
39 spanned = new SpannedString(source);
40 }
41
42 @AfterExperiment
43 protected void tearDown() {
44 spanned = null;
45 }
46
47 @Benchmark
48 public void timeCopyConstructor(int reps) throws Exception {
49 for (int i = 0; i < reps; i++) {
50 new SpannedString(spanned);
51 }
52 }
53
54 @Benchmark
55 public void timeSubsequence(int reps) throws Exception {
56 for (int i = 0; i < reps; i++) {
57 spanned.subSequence(1, spanned.length()-1);
58 }
59 }
60
61 }