• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (C) 2016 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  public class StringIndexOfBenchmark {
18      public static final String string36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";  // length = 36
19  
timeIndexOf0(int count)20      public void timeIndexOf0(int count) {
21          final char c = '0';
22          String s = string36;
23          for (int i = 0; i < count; ++i) {
24              $noinline$indexOf(s, c);
25          }
26      }
27  
timeIndexOf1(int count)28      public void timeIndexOf1(int count) {
29          final char c = '1';
30          String s = string36;
31          for (int i = 0; i < count; ++i) {
32              $noinline$indexOf(s, c);
33          }
34      }
35  
timeIndexOf2(int count)36      public void timeIndexOf2(int count) {
37          final char c = '2';
38          String s = string36;
39          for (int i = 0; i < count; ++i) {
40              $noinline$indexOf(s, c);
41          }
42      }
43  
timeIndexOf3(int count)44      public void timeIndexOf3(int count) {
45          final char c = '3';
46          String s = string36;
47          for (int i = 0; i < count; ++i) {
48              $noinline$indexOf(s, c);
49          }
50      }
51  
timeIndexOf4(int count)52      public void timeIndexOf4(int count) {
53          final char c = '4';
54          String s = string36;
55          for (int i = 0; i < count; ++i) {
56              $noinline$indexOf(s, c);
57          }
58      }
59  
timeIndexOf7(int count)60      public void timeIndexOf7(int count) {
61          final char c = '7';
62          String s = string36;
63          for (int i = 0; i < count; ++i) {
64              $noinline$indexOf(s, c);
65          }
66      }
67  
timeIndexOf8(int count)68      public void timeIndexOf8(int count) {
69          final char c = '8';
70          String s = string36;
71          for (int i = 0; i < count; ++i) {
72              $noinline$indexOf(s, c);
73          }
74      }
75  
timeIndexOfF(int count)76      public void timeIndexOfF(int count) {
77          final char c = 'F';
78          String s = string36;
79          for (int i = 0; i < count; ++i) {
80              $noinline$indexOf(s, c);
81          }
82      }
83  
timeIndexOfG(int count)84      public void timeIndexOfG(int count) {
85          final char c = 'G';
86          String s = string36;
87          for (int i = 0; i < count; ++i) {
88              $noinline$indexOf(s, c);
89          }
90      }
91  
timeIndexOfV(int count)92      public void timeIndexOfV(int count) {
93          final char c = 'V';
94          String s = string36;
95          for (int i = 0; i < count; ++i) {
96              $noinline$indexOf(s, c);
97          }
98      }
99  
timeIndexOfW(int count)100      public void timeIndexOfW(int count) {
101          final char c = 'W';
102          String s = string36;
103          for (int i = 0; i < count; ++i) {
104              $noinline$indexOf(s, c);
105          }
106      }
107  
timeIndexOf_(int count)108      public void timeIndexOf_(int count) {
109          final char c = '_';
110          String s = string36;
111          for (int i = 0; i < count; ++i) {
112              $noinline$indexOf(s, c);
113          }
114      }
115  
$noinline$indexOf(String s, char c)116      static int $noinline$indexOf(String s, char c) {
117          if (doThrow) { throw new Error(); }
118          return s.indexOf(c);
119      }
120  
121      public static boolean doThrow = false;
122  }
123