]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/perf/ubrkperf/ubrkperf.h
ICU-66108.tar.gz
[apple/icu.git] / icuSources / test / perf / ubrkperf / ubrkperf.h
CommitLineData
b75a7d8f 1/*
f3c0d7a5
A
2***********************************************************************
3* © 2016 and later: Unicode, Inc. and others.
4* License & terms of use: http://www.unicode.org/copyright.html#License
5***********************************************************************
b75a7d8f 6**********************************************************************
4388f060 7* Copyright (c) 2002-2011, International Business Machines
b75a7d8f
A
8* Corporation and others. All Rights Reserved.
9**********************************************************************
10**********************************************************************
11*/
12#ifndef _UBRKPERF_H
13#define _UBRKPERF_H
14
73c04bcf 15#include "unicode/uperf.h"
b75a7d8f
A
16
17#include <unicode/brkiter.h>
18
19class ICUBreakFunction : public UPerfFunction {
20protected:
21 BreakIterator *m_brkIt_;
22 const UChar *m_file_;
23 int32_t m_fileLen_;
24 int32_t m_noBreaks_;
25 UErrorCode m_status_;
26public:
27 ICUBreakFunction(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
28 m_brkIt_(NULL),
29 m_file_(file),
30 m_fileLen_(file_len),
31 m_noBreaks_(-1),
32 m_status_(U_ZERO_ERROR)
33 {
34 switch(mode[0]) {
35 case 'c' :
36 m_brkIt_ = BreakIterator::createCharacterInstance(locale, m_status_);
37 break;
38 case 'w' :
39 m_brkIt_ = BreakIterator::createWordInstance(locale, m_status_);
40 break;
41 case 'l' :
42 m_brkIt_ = BreakIterator::createLineInstance(locale, m_status_);
43 break;
44 case 's' :
45 m_brkIt_ = BreakIterator::createSentenceInstance(locale, m_status_);
46 break;
47 default:
48 // should not happen as we already check for this in the caller
49 m_status_ = U_ILLEGAL_ARGUMENT_ERROR;
50 break;
51 }
52 }
53
54 ~ICUBreakFunction() { delete m_brkIt_; }
55 virtual void call(UErrorCode *status) = 0;
56 virtual long getOperationsPerIteration() { return m_fileLen_; }
57 virtual long getEventsPerIteration() { return m_noBreaks_; }
58 virtual UErrorCode getStatus() { return m_status_; }
59};
60
61class ICUIsBound : public ICUBreakFunction {
62public:
63 ICUIsBound(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
64 ICUBreakFunction(locale, mode, file, file_len)
65 {
66 m_noBreaks_ = 0;
67 m_brkIt_->setText(UnicodeString(m_file_, m_fileLen_));
68 m_brkIt_->first();
69 int32_t j = 0;
70 for(j = 0; j < m_fileLen_; j++) {
71 if(m_brkIt_->isBoundary(j)) {
72 m_noBreaks_++;
73 }
74 }
75 }
76 virtual void call(UErrorCode *status)
77 {
78 m_noBreaks_ = 0;
79 int32_t j = 0;
80 for(j = 0; j < m_fileLen_; j++) {
81 if(m_brkIt_->isBoundary(j)) {
82 m_noBreaks_++;
83 }
84 }
85 }
86};
87
88class ICUForward : public ICUBreakFunction {
89public:
90 ICUForward(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
91 ICUBreakFunction(locale, mode, file, file_len)
92 {
93 m_noBreaks_ = 0;
94 m_brkIt_->setText(UnicodeString(m_file_, m_fileLen_));
95 m_brkIt_->first();
96 while(m_brkIt_->next() != BreakIterator::DONE) {
97 m_noBreaks_++;
98 }
99 }
100 virtual void call(UErrorCode *status)
101 {
102 m_noBreaks_ = 0;
103 m_brkIt_->first();
104 while(m_brkIt_->next() != BreakIterator::DONE) {
105 m_noBreaks_++;
106 }
107 }
108};
109
110class DarwinBreakFunction : public UPerfFunction {
b75a7d8f
A
111public:
112 virtual void call(UErrorCode *status) {};
b75a7d8f
A
113};
114
115class BreakIteratorPerformanceTest : public UPerfTest {
116private:
117 const char* m_mode_;
118 const UChar* m_file_;
119 int32_t m_fileLen_;
120
121public:
122 BreakIteratorPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status);
123 ~BreakIteratorPerformanceTest();
124
125 virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
126 const char* &name, char* par = NULL);
127
128 UPerfFunction* TestICUForward();
129 UPerfFunction* TestICUIsBound();
130
131 UPerfFunction* TestDarwinForward();
132 UPerfFunction* TestDarwinIsBound();
133
134};
135
136#endif // UBRKPERF_H