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