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