1/* 2 * Copyright (C) 2007 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 17package android.core; 18 19import java.util.ArrayList; 20import android.test.PerformanceTestBase; 21 22public class ArrayListPerformanceTest extends PerformanceTestBase { 23 24 private ArrayList<Integer> mList; 25 26 @Override 27 @SuppressWarnings("unchecked") 28 protected void setUp() throws Exception { 29 super.setUp(); 30 31 mList = new ArrayList(); 32 mList.add(0); 33 mList.add(1); 34 mList.add(2); 35 mList.add(3); 36 mList.add(4); 37 mList.add(5); 38 mList.add(6); 39 mList.add(7); 40 mList.add(8); 41 mList.add(9); 42 } 43 44 public void testArrayListAdd() { 45 int i = 0; 46 for (; i < 10; i++) { 47 mList.add(i); 48 mList.add(i); 49 mList.add(i); 50 mList.add(i); 51 mList.add(i); 52 mList.add(i); 53 mList.add(i); 54 mList.add(i); 55 mList.add(i); 56 mList.add(i); 57 } 58 } 59 60 public void testArrayListAdd1() { 61 int i = 0; 62 for (; i < 10; i++) { 63 mList.add(7, i); 64 mList.add(7, i); 65 mList.add(7, i); 66 mList.add(7, i); 67 mList.add(7, i); 68 mList.add(7, i); 69 mList.add(7, i); 70 mList.add(7, i); 71 mList.add(7, i); 72 mList.add(7, i); 73 } 74 } 75 76 public void testArrayListToArray() { 77 Object rArray; 78 int i = 0; 79 for (; i < 100; i++) { 80 rArray = mList.toArray(); 81 rArray = mList.toArray(); 82 rArray = mList.toArray(); 83 rArray = mList.toArray(); 84 rArray = mList.toArray(); 85 rArray = mList.toArray(); 86 rArray = mList.toArray(); 87 rArray = mList.toArray(); 88 rArray = mList.toArray(); 89 rArray = mList.toArray(); 90 } 91 } 92 93 public void testArrayListSize() { 94 int i = 0, len; 95 for (; i < 100; i++) { 96 len = mList.size(); 97 len = mList.size(); 98 len = mList.size(); 99 len = mList.size(); 100 len = mList.size(); 101 len = mList.size(); 102 len = mList.size(); 103 len = mList.size(); 104 len = mList.size(); 105 len = mList.size(); 106 } 107 } 108 109 public void testArrayListGet() { 110 int i = 0, value; 111 int len = mList.size(); 112 for (; i < len; i++) { 113 value = mList.get(i); 114 value = mList.get(i); 115 value = mList.get(i); 116 value = mList.get(i); 117 value = mList.get(i); 118 value = mList.get(i); 119 value = mList.get(i); 120 value = mList.get(i); 121 value = mList.get(i); 122 value = mList.get(i); 123 } 124 } 125 126 public void testArrayListContains() { 127 boolean flag; 128 int i = 0; 129 130 for (; i < 100; i++) { 131 flag = mList.contains(i); 132 flag = mList.contains(i); 133 flag = mList.contains(i); 134 flag = mList.contains(i); 135 flag = mList.contains(i); 136 flag = mList.contains(i); 137 flag = mList.contains(i); 138 flag = mList.contains(i); 139 flag = mList.contains(i); 140 flag = mList.contains(i); 141 142 } 143 } 144 145 public void testArrayListToArray1() { 146 Integer[] rArray = new Integer[10]; 147 148 Integer[] mArray; 149 int i = 0; 150 for (; i < 100; i++) { 151 mArray = mList.toArray(rArray); 152 mArray = mList.toArray(rArray); 153 mArray = mList.toArray(rArray); 154 mArray = mList.toArray(rArray); 155 mArray = mList.toArray(rArray); 156 mArray = mList.toArray(rArray); 157 mArray = mList.toArray(rArray); 158 mArray = mList.toArray(rArray); 159 mArray = mList.toArray(rArray); 160 mArray = mList.toArray(rArray); 161 } 162 } 163 164 public void testArrayListSet() { 165 int i = 0; 166 for (; i < 10; i++) { 167 mList.set(5, 0); 168 mList.set(5, 0); 169 mList.set(5, 0); 170 mList.set(5, 0); 171 mList.set(5, 0); 172 mList.set(5, 0); 173 mList.set(5, 0); 174 mList.set(5, 0); 175 mList.set(5, 0); 176 mList.set(5, 0); 177 } 178 } 179 180 public void testArrayListIndexOf() { 181 int i = 0, index; 182 183 for (; i < 100; i++) { 184 index = mList.indexOf(0); 185 index = mList.indexOf(0); 186 index = mList.indexOf(0); 187 index = mList.indexOf(0); 188 index = mList.indexOf(0); 189 index = mList.indexOf(0); 190 index = mList.indexOf(0); 191 index = mList.indexOf(0); 192 index = mList.indexOf(0); 193 index = mList.indexOf(0); 194 } 195 } 196 197 public void testArrayListLastIndexOf() { 198 int i = 0, index; 199 200 for (; i < 100; i++) { 201 index = mList.lastIndexOf(0); 202 index = mList.lastIndexOf(0); 203 index = mList.lastIndexOf(0); 204 index = mList.lastIndexOf(0); 205 index = mList.lastIndexOf(0); 206 index = mList.lastIndexOf(0); 207 index = mList.lastIndexOf(0); 208 index = mList.lastIndexOf(0); 209 index = mList.lastIndexOf(0); 210 index = mList.lastIndexOf(0); 211 } 212 } 213 214 @SuppressWarnings("unchecked") 215 public void testArrayListRemove() { 216 ArrayList<Integer> aList; 217 aList = new ArrayList(); 218 for (int j = 0; j < 10000; j++) { 219 aList.add(0); 220 } 221 222 int i = 0, index; 223 224 for (; i < 10; i++) { 225 index = aList.remove(0); 226 index = aList.remove(0); 227 index = aList.remove(0); 228 index = aList.remove(0); 229 index = aList.remove(0); 230 index = aList.remove(0); 231 index = aList.remove(0); 232 index = aList.remove(0); 233 index = aList.remove(0); 234 index = aList.remove(0); 235 236 237 } 238 } 239 240 @SuppressWarnings("unchecked") 241 public void testArrayListAddAll() { 242 ArrayList<Integer> aList = new ArrayList(); 243 244 int i = 0; 245 boolean b; 246 for (; i < 10; i++) { 247 b = aList.addAll(mList); 248 b = aList.addAll(mList); 249 b = aList.addAll(mList); 250 b = aList.addAll(mList); 251 b = aList.addAll(mList); 252 b = aList.addAll(mList); 253 b = aList.addAll(mList); 254 b = aList.addAll(mList); 255 b = aList.addAll(mList); 256 b = aList.addAll(mList); 257 258 } 259 } 260 261 @SuppressWarnings("unchecked") 262 public void testArrayListRemove1() { 263 ArrayList<String> aList; 264 String s; 265 266 aList = new ArrayList(); 267 for (int j = 0; j < 100; j++) { 268 aList.add("a"); 269 aList.add("b"); 270 } 271 s = new String("a"); 272 273 int i = 0; 274 boolean b; 275 for (; i < 10; i++) { 276 b = aList.remove(s); 277 b = aList.remove(s); 278 b = aList.remove(s); 279 b = aList.remove(s); 280 b = aList.remove(s); 281 b = aList.remove(s); 282 b = aList.remove(s); 283 b = aList.remove(s); 284 b = aList.remove(s); 285 b = aList.remove(s); 286 } 287 } 288 289 @SuppressWarnings("unchecked") 290 public void testArrayListAddAll1() { 291 ArrayList<Integer> aList = new ArrayList(); 292 293 int i = 0; 294 boolean b; 295 296 for (; i < 10; i++) { 297 b = aList.addAll(0, mList); 298 b = aList.addAll(0, mList); 299 b = aList.addAll(0, mList); 300 b = aList.addAll(0, mList); 301 b = aList.addAll(0, mList); 302 b = aList.addAll(0, mList); 303 b = aList.addAll(0, mList); 304 b = aList.addAll(0, mList); 305 b = aList.addAll(0, mList); 306 b = aList.addAll(0, mList); 307 } 308 } 309 310 public void testArrayListClone() { 311 Object rObj; 312 int i = 0; 313 314 for (; i < 100; i++) { 315 rObj = mList.clone(); 316 rObj = mList.clone(); 317 rObj = mList.clone(); 318 rObj = mList.clone(); 319 rObj = mList.clone(); 320 rObj = mList.clone(); 321 rObj = mList.clone(); 322 rObj = mList.clone(); 323 rObj = mList.clone(); 324 rObj = mList.clone(); 325 } 326 } 327} 328