]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/charperf/charperf.h
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / test / perf / charperf / charperf.h
1 /*
2 **********************************************************************
3 * Copyright (c) 2002-2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 **********************************************************************
7 */
8 #ifndef _CHARPERF_H
9 #define _CHARPERF_H
10
11 #include "uperf.h"
12 #include "unicode/uchar.h"
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <wchar.h>
16 #include <wctype.h>
17
18 typedef void (*CharPerfFn)(UChar32 ch);
19 typedef void (*StdLibCharPerfFn)(wchar_t ch);
20
21 class CharPerfFunction : public UPerfFunction
22 {
23 public:
24 virtual void call(UErrorCode* status)
25 {
26 for (UChar32 i = MIN_; i < MAX_; i ++) {
27 (*m_fn_)(i);
28 }
29 }
30
31 virtual long getOperationsPerIteration()
32 {
33 return MAX_ - MIN_;
34 }
35 CharPerfFunction(CharPerfFn func, UChar32 min, UChar32 max)
36 {
37 m_fn_ = func;
38 MIN_ = min;
39 MAX_ = max;
40 }
41
42 private:
43 CharPerfFn m_fn_;
44 UChar32 MIN_;
45 UChar32 MAX_;
46 };
47
48 class StdLibCharPerfFunction : public UPerfFunction
49 {
50 public:
51 virtual void call(UErrorCode* status)
52 {
53 // note wchar_t is unsigned, it will revert to 0 once it reaches
54 // 65535
55 for (wchar_t i = MIN_; i < MAX_; i ++) {
56 (*m_fn_)(i);
57 }
58 }
59
60 virtual long getOperationsPerIteration()
61 {
62 return MAX_ - MIN_;
63 }
64
65 StdLibCharPerfFunction(StdLibCharPerfFn func, wchar_t min, wchar_t max)
66 {
67 m_fn_ = func;
68 MIN_ = min;
69 MAX_ = max;
70 }
71
72 ~StdLibCharPerfFunction()
73 {
74 }
75
76 private:
77 StdLibCharPerfFn m_fn_;
78 wchar_t MIN_;
79 wchar_t MAX_;
80 };
81
82 class CharPerformanceTest : public UPerfTest
83 {
84 public:
85 CharPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status);
86 ~CharPerformanceTest();
87 virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
88 const char *&name,
89 char *par = NULL);
90 UPerfFunction* TestIsAlpha();
91 UPerfFunction* TestIsUpper();
92 UPerfFunction* TestIsLower();
93 UPerfFunction* TestIsDigit();
94 UPerfFunction* TestIsSpace();
95 UPerfFunction* TestIsAlphaNumeric();
96 UPerfFunction* TestIsPrint();
97 UPerfFunction* TestIsControl();
98 UPerfFunction* TestToLower();
99 UPerfFunction* TestToUpper();
100 UPerfFunction* TestIsWhiteSpace();
101 UPerfFunction* TestStdLibIsAlpha();
102 UPerfFunction* TestStdLibIsUpper();
103 UPerfFunction* TestStdLibIsLower();
104 UPerfFunction* TestStdLibIsDigit();
105 UPerfFunction* TestStdLibIsSpace();
106 UPerfFunction* TestStdLibIsAlphaNumeric();
107 UPerfFunction* TestStdLibIsPrint();
108 UPerfFunction* TestStdLibIsControl();
109 UPerfFunction* TestStdLibToLower();
110 UPerfFunction* TestStdLibToUpper();
111 UPerfFunction* TestStdLibIsWhiteSpace();
112
113 private:
114 UChar32 MIN_;
115 UChar32 MAX_;
116 };
117
118 inline void isAlpha(UChar32 ch)
119 {
120 u_isalpha(ch);
121 }
122
123 inline void isUpper(UChar32 ch)
124 {
125 u_isupper(ch);
126 }
127
128 inline void isLower(UChar32 ch)
129 {
130 u_islower(ch);
131 }
132
133 inline void isDigit(UChar32 ch)
134 {
135 u_isdigit(ch);
136 }
137
138 inline void isSpace(UChar32 ch)
139 {
140 u_isspace(ch);
141 }
142
143 inline void isAlphaNumeric(UChar32 ch)
144 {
145 u_isalnum(ch);
146 }
147
148 /**
149 * This test may be different since c lib has a type PUNCT and it is printable.
150 * iswgraph is not used for testing since it is a subset of iswprint with the
151 * exception of returning true for white spaces. no match found in icu4c.
152 */
153 inline void isPrint(UChar32 ch)
154 {
155 u_isprint(ch);
156 }
157
158 inline void isControl(UChar32 ch)
159 {
160 u_iscntrl(ch);
161 }
162
163 inline void toLower(UChar32 ch)
164 {
165 u_tolower(ch);
166 }
167
168 inline void toUpper(UChar32 ch)
169 {
170 u_toupper(ch);
171 }
172
173 inline void isWhiteSpace(UChar32 ch)
174 {
175 u_isWhitespace(ch);
176 }
177
178 inline void StdLibIsAlpha(wchar_t ch)
179 {
180 iswalpha(ch);
181 }
182
183 inline void StdLibIsUpper(wchar_t ch)
184 {
185 iswupper(ch);
186 }
187
188 inline void StdLibIsLower(wchar_t ch)
189 {
190 iswlower(ch);
191 }
192
193 inline void StdLibIsDigit(wchar_t ch)
194 {
195 iswdigit(ch);
196 }
197
198 inline void StdLibIsSpace(wchar_t ch)
199 {
200 iswspace(ch);
201 }
202
203 inline void StdLibIsAlphaNumeric(wchar_t ch)
204 {
205 iswalnum(ch);
206 }
207
208 /**
209 * This test may be different since c lib has a type PUNCT and it is printable.
210 * iswgraph is not used for testing since it is a subset of iswprint with the
211 * exception of returning true for white spaces. no match found in icu4c.
212 */
213 inline void StdLibIsPrint(wchar_t ch)
214 {
215 iswprint(ch);
216 }
217
218 inline void StdLibIsControl(wchar_t ch)
219 {
220 iswcntrl(ch);
221 }
222
223 inline void StdLibToLower(wchar_t ch)
224 {
225 towlower(ch);
226 }
227
228 inline void StdLibToUpper(wchar_t ch)
229 {
230 towupper(ch);
231 }
232
233 inline void StdLibIsWhiteSpace(wchar_t ch)
234 {
235 iswspace(ch);
236 }
237
238 #endif // CHARPERF_H