2 **********************************************************************
\r
3 * Copyright (c) 2002-2007, International Business Machines
\r
4 * Corporation and others. All Rights Reserved.
\r
5 **********************************************************************
\r
7 package com.ibm.icu.dev.test.perf;
\r
8 import com.ibm.icu.text.*;
\r
9 import java.util.HashSet;
\r
10 import java.util.Iterator;
\r
13 * A class for testing UnicodeSet performance.
\r
18 public class UnicodeSetPerf extends PerfTest {
\r
21 UnicodeSet testChars;
\r
22 UnicodeSetIterator it;
\r
26 public static void main(String[] args) throws Exception {
\r
27 new UnicodeSetPerf().run(args);
\r
30 protected void setup(String[] args) {
\r
31 // We only take one argument, the pattern
\r
32 if (args.length != 1) {
\r
33 throw new RuntimeException("Please supply UnicodeSet pattern");
\r
37 testChars = new UnicodeSet(pattern);
\r
38 it = new UnicodeSetIterator(testChars);
\r
39 us = new UnicodeSet();
\r
43 PerfTest.Function testUnicodeSetAdd() {
\r
44 return new PerfTest.Function() {
\r
45 public void call() {
\r
49 while (it.nextRange()) {
\r
50 for (int cp = it.codepoint; cp <= it.codepointEnd; ++cp) {
\r
57 public long getOperationsPerIteration() {
\r
58 return testChars.size();
\r
63 PerfTest.Function testHashSetAdd() {
\r
64 return new PerfTest.Function() {
\r
65 public void call() {
\r
69 while (it.nextRange()) {
\r
70 for (int cp = it.codepoint; cp <= it.codepointEnd; ++cp) {
\r
71 hs.add(new Integer(cp));
\r
77 public long getOperationsPerIteration() {
\r
78 return testChars.size();
\r
83 PerfTest.Function testUnicodeSetContains() {
\r
87 return new PerfTest.Function() {
\r
88 public void call() {
\r
90 for (int cp = 0; cp <= 0x10FFFF; ++cp) {
\r
91 if (us.contains(cp)) {
\r
97 public long getOperationsPerIteration() {
\r
103 PerfTest.Function testHashSetContains() {
\r
106 while (it.next()) {
\r
107 hs.add(new Integer(it.codepoint));
\r
109 return new PerfTest.Function() {
\r
110 public void call() {
\r
112 for (int cp = 0; cp <= 0x10FFFF; ++cp) {
\r
113 if (hs.contains(new Integer(cp))) {
\r
119 public long getOperationsPerIteration() {
\r
125 PerfTest.Function testUnicodeSetIterate() {
\r
126 return new PerfTest.Function() {
\r
127 public void call() {
\r
129 UnicodeSetIterator uit = new UnicodeSetIterator(testChars);
\r
130 while (uit.next()) {
\r
131 temp += uit.codepoint;
\r
135 public long getOperationsPerIteration() {
\r
136 return testChars.size();
\r
141 PerfTest.Function testHashSetIterate() {
\r
144 while (it.next()) {
\r
145 hs.add(new Integer(it.codepoint));
\r
147 return new PerfTest.Function() {
\r
148 public void call() {
\r
150 Iterator itr = hs.iterator();
\r
151 while (itr.hasNext()) {
\r
152 temp += ((Integer)itr.next()).intValue();
\r
156 public long getOperationsPerIteration() {
\r
157 return testChars.size();
\r