1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /** 4 ******************************************************************************* 5 * Copyright (C) 2001-2004, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9 10 package com.ibm.icu.dev.test.perf; 11 12 import com.ibm.icu.lang.UCharacter; 13 14 /** 15 * Base performance test that takes in a method name for testing with JDK. 16 * To use 17 * <code> 18 * java com.ibm.icu.dev.test.perf.UCharacterPerf $MethodName $LoopCount - 19 * $START_TEST_CHARACTER $END_TEST_CHARACTER 20 * </code> 21 * where $*_TEST_CHARACTER are in hex decimals with a leading 0x 22 */ 23 public final class UCharacterPerf extends PerfTest 24 { 25 // public methods ------------------------------------------------------ 26 27 public static void main(String[] args) throws Exception 28 { 29 new UCharacterPerf().run(args); 30 // new UCharacterPerf().TestPerformance(); 31 } 32 33 protected void setup(String[] args) { 34 // We only take one argument, the pattern 35 MIN_ = Character.MIN_VALUE; 36 MAX_ = Character.MAX_VALUE; 37 if (args.length >= 1) { 38 MIN_ = Integer.parseInt(args[0], 16); 39 } 40 if (args.length >= 2) { 41 MAX_ = Integer.parseInt(args[1], 16); 42 } 43 } 44 45 PerfTest.Function testDigit() 46 { 47 return new PerfTest.Function() { 48 public void call() { 49 for (int ch = MIN_; ch < MAX_; ch ++) { 50 UCharacter.digit(ch, 10); 51 } 52 } 53 54 public long getOperationsPerIteration() { 55 return MAX_ - MIN_ + 1; 56 } 57 }; 58 } 59 60 PerfTest.Function testJDKDigit() 61 { 62 return new PerfTest.Function() { 63 public void call() { 64 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 65 Character.digit(ch, 10); 66 } 67 } 68 69 public long getOperationsPerIteration() { 70 return MAX_ - MIN_ + 1; 71 } 72 }; 73 } 74 75 PerfTest.Function testGetNumericValue() 76 { 77 return new PerfTest.Function() { 78 public void call() { 79 for (int ch = MIN_; ch < MAX_; ch ++) { 80 UCharacter.getNumericValue(ch); 81 } 82 } 83 84 public long getOperationsPerIteration() { 85 return MAX_ - MIN_ + 1; 86 } 87 }; 88 } 89 90 PerfTest.Function testJDKGetNumericValue() 91 { 92 return new PerfTest.Function() { 93 public void call() { 94 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 95 Character.getNumericValue(ch); 96 } 97 } 98 99 public long getOperationsPerIteration() { 100 return MAX_ - MIN_ + 1; 101 } 102 }; 103 } 104 105 PerfTest.Function testGetType() 106 { 107 return new PerfTest.Function() { 108 public void call() { 109 for (int ch = MIN_; ch < MAX_; ch ++) { 110 UCharacter.getType(ch); 111 } 112 } 113 114 public long getOperationsPerIteration() { 115 return MAX_ - MIN_ + 1; 116 } 117 }; 118 } 119 120 PerfTest.Function testJDKGetType() 121 { 122 return new PerfTest.Function() { 123 public void call() { 124 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 125 Character.getType(ch); 126 } 127 } 128 129 public long getOperationsPerIteration() { 130 return MAX_ - MIN_ + 1; 131 } 132 }; 133 } 134 135 PerfTest.Function testIsDefined() 136 { 137 return new PerfTest.Function() { 138 public void call() { 139 for (int ch = MIN_; ch < MAX_; ch ++) { 140 UCharacter.isDefined(ch); 141 } 142 } 143 144 public long getOperationsPerIteration() { 145 return MAX_ - MIN_ + 1; 146 } 147 }; 148 } 149 150 PerfTest.Function testJDKIsDefined() 151 { 152 return new PerfTest.Function() { 153 public void call() { 154 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 155 Character.isDefined(ch); 156 } 157 } 158 159 public long getOperationsPerIteration() { 160 return MAX_ - MIN_ + 1; 161 } 162 }; 163 } 164 165 PerfTest.Function testIsDigit() 166 { 167 return new PerfTest.Function() { 168 public void call() { 169 for (int ch = MIN_; ch < MAX_; ch ++) { 170 UCharacter.isDigit(ch); 171 } 172 } 173 174 public long getOperationsPerIteration() { 175 return MAX_ - MIN_ + 1; 176 } 177 }; 178 } 179 180 PerfTest.Function testJDKIsDigit() 181 { 182 return new PerfTest.Function() { 183 public void call() { 184 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 185 Character.isDigit(ch); 186 } 187 } 188 189 public long getOperationsPerIteration() { 190 return MAX_ - MIN_ + 1; 191 } 192 }; 193 } 194 195 PerfTest.Function testIsIdentifierIgnorable() 196 { 197 return new PerfTest.Function() { 198 public void call() { 199 for (int ch = MIN_; ch < MAX_; ch ++) { 200 UCharacter.isIdentifierIgnorable(ch); 201 } 202 } 203 204 public long getOperationsPerIteration() { 205 return MAX_ - MIN_ + 1; 206 } 207 }; 208 } 209 210 PerfTest.Function testJDKIsIdentifierIgnorable() 211 { 212 return new PerfTest.Function() { 213 public void call() { 214 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 215 Character.isIdentifierIgnorable(ch); 216 } 217 } 218 219 public long getOperationsPerIteration() { 220 return MAX_ - MIN_ + 1; 221 } 222 }; 223 } 224 225 PerfTest.Function testIsISOControl() 226 { 227 return new PerfTest.Function() { 228 public void call() { 229 for (int ch = MIN_; ch < MAX_; ch ++) { 230 UCharacter.isISOControl(ch); 231 } 232 } 233 234 public long getOperationsPerIteration() { 235 return MAX_ - MIN_ + 1; 236 } 237 }; 238 } 239 240 PerfTest.Function testJDKIsISOControl() 241 { 242 return new PerfTest.Function() { 243 public void call() { 244 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 245 Character.isISOControl(ch); 246 } 247 } 248 249 public long getOperationsPerIteration() { 250 return MAX_ - MIN_ + 1; 251 } 252 }; 253 } 254 255 PerfTest.Function testIsLetter() 256 { 257 return new PerfTest.Function() { 258 public void call() { 259 for (int ch = MIN_; ch < MAX_; ch ++) { 260 UCharacter.isLetter(ch); 261 } 262 } 263 264 public long getOperationsPerIteration() { 265 return MAX_ - MIN_ + 1; 266 } 267 }; 268 } 269 270 PerfTest.Function testJDKIsLetter() 271 { 272 return new PerfTest.Function() { 273 public void call() { 274 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 275 Character.isLetter(ch); 276 } 277 } 278 279 public long getOperationsPerIteration() { 280 return MAX_ - MIN_ + 1; 281 } 282 }; 283 } 284 285 PerfTest.Function testIsLetterOrDigit() 286 { 287 return new PerfTest.Function() { 288 public void call() { 289 for (int ch = MIN_; ch < MAX_; ch ++) { 290 UCharacter.isLetterOrDigit(ch); 291 } 292 } 293 294 public long getOperationsPerIteration() { 295 return MAX_ - MIN_ + 1; 296 } 297 }; 298 } 299 300 PerfTest.Function testJDKIsLetterOrDigit() 301 { 302 return new PerfTest.Function() { 303 public void call() { 304 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 305 Character.isLetterOrDigit(ch); 306 } 307 } 308 309 public long getOperationsPerIteration() { 310 return MAX_ - MIN_ + 1; 311 } 312 }; 313 } 314 315 PerfTest.Function testIsLowerCase() 316 { 317 return new PerfTest.Function() { 318 public void call() { 319 for (int ch = MIN_; ch < MAX_; ch ++) { 320 UCharacter.isLowerCase(ch); 321 } 322 } 323 324 public long getOperationsPerIteration() { 325 return MAX_ - MIN_ + 1; 326 } 327 }; 328 } 329 330 PerfTest.Function testJDKIsLowerCase() 331 { 332 return new PerfTest.Function() { 333 public void call() { 334 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 335 Character.isLowerCase(ch); 336 } 337 } 338 339 public long getOperationsPerIteration() { 340 return MAX_ - MIN_ + 1; 341 } 342 }; 343 } 344 345 PerfTest.Function testIsSpaceChar() 346 { 347 return new PerfTest.Function() { 348 public void call() { 349 for (int ch = MIN_; ch < MAX_; ch ++) { 350 UCharacter.isSpaceChar(ch); 351 } 352 } 353 354 public long getOperationsPerIteration() { 355 return MAX_ - MIN_ + 1; 356 } 357 }; 358 } 359 360 PerfTest.Function testJDKIsSpaceChar() 361 { 362 return new PerfTest.Function() { 363 public void call() { 364 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 365 Character.isSpaceChar(ch); 366 } 367 } 368 369 public long getOperationsPerIteration() { 370 return MAX_ - MIN_ + 1; 371 } 372 }; 373 } 374 375 PerfTest.Function testIsTitleCase() 376 { 377 return new PerfTest.Function() { 378 public void call() { 379 for (int ch = MIN_; ch < MAX_; ch ++) { 380 UCharacter.isTitleCase(ch); 381 } 382 } 383 384 public long getOperationsPerIteration() { 385 return MAX_ - MIN_ + 1; 386 } 387 }; 388 } 389 390 PerfTest.Function testJDKIsTitleCase() 391 { 392 return new PerfTest.Function() { 393 public void call() { 394 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 395 Character.isTitleCase(ch); 396 } 397 } 398 399 public long getOperationsPerIteration() { 400 return MAX_ - MIN_ + 1; 401 } 402 }; 403 } 404 405 PerfTest.Function testIsUnicodeIdentifierPart() 406 { 407 return new PerfTest.Function() { 408 public void call() { 409 for (int ch = MIN_; ch < MAX_; ch ++) { 410 UCharacter.isUnicodeIdentifierPart(ch); 411 } 412 } 413 414 public long getOperationsPerIteration() { 415 return MAX_ - MIN_ + 1; 416 } 417 }; 418 } 419 420 PerfTest.Function testJDKIsUnicodeIdentifierPart() 421 { 422 return new PerfTest.Function() { 423 public void call() { 424 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 425 Character.isUnicodeIdentifierPart(ch); 426 } 427 } 428 429 public long getOperationsPerIteration() { 430 return MAX_ - MIN_ + 1; 431 } 432 }; 433 } 434 435 PerfTest.Function testIsUnicodeIdentifierStart() 436 { 437 return new PerfTest.Function() { 438 public void call() { 439 for (int ch = MIN_; ch < MAX_; ch ++) { 440 UCharacter.isUnicodeIdentifierStart(ch); 441 } 442 } 443 444 public long getOperationsPerIteration() { 445 return MAX_ - MIN_ + 1; 446 } 447 }; 448 } 449 450 PerfTest.Function testJDKIsUnicodeIdentifierStart() 451 { 452 return new PerfTest.Function() { 453 public void call() { 454 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 455 Character.isUnicodeIdentifierStart(ch); 456 } 457 } 458 459 public long getOperationsPerIteration() { 460 return MAX_ - MIN_ + 1; 461 } 462 }; 463 } 464 465 PerfTest.Function testIsUpperCase() 466 { 467 return new PerfTest.Function() { 468 public void call() { 469 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 470 UCharacter.isUpperCase(ch); 471 } 472 } 473 474 public long getOperationsPerIteration() { 475 return MAX_ - MIN_ + 1; 476 } 477 }; 478 } 479 480 PerfTest.Function testJDKIsUpperCase() 481 { 482 return new PerfTest.Function() { 483 public void call() { 484 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 485 Character.isUpperCase(ch); 486 } 487 } 488 489 public long getOperationsPerIteration() { 490 return MAX_ - MIN_ + 1; 491 } 492 }; 493 } 494 495 PerfTest.Function testIsWhiteSpace() 496 { 497 return new PerfTest.Function() { 498 public void call() { 499 for (int ch = MIN_; ch < MAX_; ch ++) { 500 UCharacter.isWhitespace(ch); 501 } 502 } 503 504 public long getOperationsPerIteration() { 505 return MAX_ - MIN_ + 1; 506 } 507 }; 508 } 509 510 PerfTest.Function testJDKIsWhiteSpace() 511 { 512 return new PerfTest.Function() { 513 public void call() { 514 for (char ch = (char)MIN_; ch < (char)MAX_; ch ++) { 515 Character.isWhitespace(ch); 516 } 517 } 518 519 public long getOperationsPerIteration() { 520 return MAX_ - MIN_ + 1; 521 } 522 }; 523 } 524 525 // private data member -------------------------------------------------- 526 527 /** 528 * Minimum codepoint to do test. Test is ran from MIN_ to MAX_ 529 */ 530 private static int MIN_; 531 /** 532 * Minimum codepoint to do test. Test is ran from MIN_ to MAX_ 533 */ 534 private static int MAX_; 535 } 536