2 **********************************************************************
3 * Copyright (c) 2002-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 package com.ibm.icu.dev.test.perf;
8 import com.ibm.icu.text.*;
9 import java.io.FileInputStream;
10 import java.io.InputStream;
11 import java.io.InputStreamReader;
12 import java.io.IOException;
13 import java.text.BreakIterator;
16 * A class for testing UnicodeSet performance.
21 public class RBBIPerf extends PerfTest {
24 RuleBasedBreakIterator bi;
28 public static void main(String[] args) throws Exception {
29 new RBBIPerf().run(args);
32 protected void setup(String[] args) {
33 // We only take one argument, the pattern
34 if (args.length != 2) {
35 throw new RuntimeException("RBBITest params: data_file_name break_iterator_type ");
39 dataFileName = args[0];
40 StringBuffer testFileBuf = new StringBuffer();
41 InputStream is = new FileInputStream(dataFileName);
42 InputStreamReader isr = new InputStreamReader(is, "UTF-8");
49 UTF16.append(testFileBuf, c);
51 testString = testFileBuf.toString();
53 catch (IOException e) {
54 throw new RuntimeException(e.toString());
57 if (args.length >= 2) {
58 if (args[1].equals("char")) {
59 bi = (RuleBasedBreakIterator)com.ibm.icu.text.BreakIterator.getCharacterInstance();
60 } else if (args[1].equals("word")) {
61 bi = (RuleBasedBreakIterator)com.ibm.icu.text.BreakIterator.getWordInstance();
62 } else if (args[1].equals("line")) {
63 bi = (RuleBasedBreakIterator)com.ibm.icu.text.BreakIterator.getLineInstance();
64 } else if (args[1].equals("jdkline")) {
65 jdkbi = BreakIterator.getLineInstance();
69 bi.setText(testString);
72 jdkbi.setText(testString);
79 PerfTest.Function testRBBINext() {
80 return new PerfTest.Function() {
86 for (; n != BreakIterator.DONE; n=bi.next()) {
90 for (; n != BreakIterator.DONE; n=jdkbi.next()) {
96 public long getOperationsPerIteration() {
100 for (n=bi.first(); n != BreakIterator.DONE; n=bi.next()) {
104 for (n=jdkbi.first(); n != BreakIterator.DONE; n=jdkbi.next()) {
114 PerfTest.Function testRBBIPrevious() {
115 return new PerfTest.Function() {
120 for (n=bi.last(); n != BreakIterator.DONE; n=bi.previous()) {
125 public long getOperationsPerIteration() {
128 for (n=bi.last(); n != BreakIterator.DONE; n=bi.previous()) {
137 PerfTest.Function testRBBIIsBoundary() {
138 return new PerfTest.Function() {
141 int n=testString.length();
143 for (i=0; i<n; i++) {
148 public long getOperationsPerIteration() {
149 int n = testString.length();