]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/charperf/charperf.cpp
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / test / perf / charperf / charperf.cpp
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (C) 2002-2016 IBM, Inc. All Rights Reserved.
4 *
5 ********************************************************************/
6 /*****************************************************************************
7 * File charperf.cpp
8 *
9 * Modification History:
10 * Name Description
11 * Syn Wee Quek First Version
12 ******************************************************************************
13 */
14
15 /**
16 * This program tests character properties performance.
17 * APIs tested:
18 * ICU4C
19 * Windows
20 */
21
22 #include "charperf.h"
23 #include "cmemory.h"
24 #include "uoptions.h"
25
26 UOption options[] = {
27 UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG),
28 UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG),
29 };
30 int MIN_OPTION_ = 0;
31 int MAX_OPTION_ = 1;
32
33 int main(int argc, const char *argv[])
34 {
35 UErrorCode status = U_ZERO_ERROR;
36 CharPerformanceTest test(argc, argv, status);
37 if (U_FAILURE(status)){
38 return status;
39 }
40 if (test.run() == FALSE){
41 fprintf(stderr, "FAILED: Tests could not be run please check the "
42 "arguments.\n");
43 return -1;
44 }
45 return 0;
46 }
47
48 CharPerformanceTest::CharPerformanceTest(int32_t argc, const char *argv[],
49 UErrorCode &status)
50 : UPerfTest(argc, argv, status)
51 {
52 if (status== U_ILLEGAL_ARGUMENT_ERROR){
53 fprintf(stderr,gUsageString, "charperf");
54 return;
55 }
56 if (U_FAILURE(status)){
57 fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n",
58 u_errorName(status));
59 return;
60 }
61
62 if (_remainingArgc < 0) {
63 // that means there are some -names not matched in the super class
64 // first tag is always skipped in u_parseArgs
65 int size = - _remainingArgc;
66 argv += argc - size;
67 argc = size;
68 _remainingArgc = u_parseArgs(argc, (char**)argv,
69 UPRV_LENGTHOF(options), options);
70 }
71 MIN_ = 0;
72 if (sizeof(wchar_t) > 2) {
73 // for stdlibs like glibc that supports 32 bits wchar
74 // we test for the whole unicode character set by default
75 MAX_ = 0x10ffff;
76 }
77 else {
78 MAX_ = 0xffff;
79 }
80 printf("MAX_ size will be 0x%x\n", MAX_);
81 if (options[MIN_OPTION_].doesOccur) {
82 MIN_ = atoi(options[MIN_OPTION_].value);
83 }
84 if (options[MAX_OPTION_].doesOccur) {
85 MAX_ = atoi(options[MAX_OPTION_].value);
86 }
87 }
88
89 CharPerformanceTest::~CharPerformanceTest()
90 {
91 }
92
93 UPerfFunction* CharPerformanceTest::runIndexedTest(int32_t index, UBool exec,
94 const char *&name,
95 char* par)
96 {
97 switch (index) {
98 TESTCASE(0, TestIsAlpha);
99 TESTCASE(1, TestIsUpper);
100 TESTCASE(2, TestIsLower);
101 TESTCASE(3, TestIsDigit);
102 TESTCASE(4, TestIsSpace);
103 TESTCASE(5, TestIsAlphaNumeric);
104 TESTCASE(6, TestIsPrint);
105 TESTCASE(7, TestIsControl);
106 TESTCASE(8, TestToLower);
107 TESTCASE(9, TestToUpper);
108 TESTCASE(10, TestIsWhiteSpace);
109 TESTCASE(11, TestStdLibIsAlpha);
110 TESTCASE(12, TestStdLibIsUpper);
111 TESTCASE(13, TestStdLibIsLower);
112 TESTCASE(14, TestStdLibIsDigit);
113 TESTCASE(15, TestStdLibIsSpace);
114 TESTCASE(16, TestStdLibIsAlphaNumeric);
115 TESTCASE(17, TestStdLibIsPrint);
116 TESTCASE(18, TestStdLibIsControl);
117 TESTCASE(19, TestStdLibToLower);
118 TESTCASE(20, TestStdLibToUpper);
119 TESTCASE(21, TestStdLibIsWhiteSpace);
120 default:
121 name = "";
122 return NULL;
123 }
124 return NULL;
125 }
126
127 UPerfFunction* CharPerformanceTest::TestIsAlpha()
128 {
129 return new CharPerfFunction(isAlpha, MIN_, MAX_);
130 }
131
132 UPerfFunction* CharPerformanceTest::TestIsUpper()
133 {
134 return new CharPerfFunction(isUpper, MIN_, MAX_);
135 }
136
137 UPerfFunction* CharPerformanceTest::TestIsLower()
138 {
139 return new CharPerfFunction(isLower, MIN_, MAX_);
140 }
141
142 UPerfFunction* CharPerformanceTest::TestIsDigit()
143 {
144 return new CharPerfFunction(isDigit, MIN_, MAX_);
145 }
146
147 UPerfFunction* CharPerformanceTest::TestIsSpace()
148 {
149 return new CharPerfFunction(isSpace, MIN_, MAX_);
150 }
151
152 UPerfFunction* CharPerformanceTest::TestIsAlphaNumeric()
153 {
154 return new CharPerfFunction(isAlphaNumeric, MIN_, MAX_);
155 }
156
157 /**
158 * This test may be different since c lib has a type PUNCT and it is printable.
159 * iswgraph is not used for testing since it is a subset of iswprint with the
160 * exception of returning true for white spaces. no match found in icu4c.
161 */
162 UPerfFunction* CharPerformanceTest::TestIsPrint()
163 {
164 return new CharPerfFunction(isPrint, MIN_, MAX_);
165 }
166
167 UPerfFunction* CharPerformanceTest::TestIsControl()
168 {
169 return new CharPerfFunction(isControl, MIN_, MAX_);
170 }
171
172 UPerfFunction* CharPerformanceTest::TestToLower()
173 {
174 return new CharPerfFunction(toLower, MIN_, MAX_);
175 }
176
177 UPerfFunction* CharPerformanceTest::TestToUpper()
178 {
179 return new CharPerfFunction(toUpper, MIN_, MAX_);
180 }
181
182 UPerfFunction* CharPerformanceTest::TestIsWhiteSpace()
183 {
184 return new CharPerfFunction(isWhiteSpace, MIN_, MAX_);
185 }
186
187 UPerfFunction* CharPerformanceTest::TestStdLibIsAlpha()
188 {
189 return new StdLibCharPerfFunction(StdLibIsAlpha, (wchar_t)MIN_,
190 (wchar_t)MAX_);
191 }
192
193 UPerfFunction* CharPerformanceTest::TestStdLibIsUpper()
194 {
195 return new StdLibCharPerfFunction(StdLibIsUpper, (wchar_t)MIN_,
196 (wchar_t)MAX_);
197 }
198
199 UPerfFunction* CharPerformanceTest::TestStdLibIsLower()
200 {
201 return new StdLibCharPerfFunction(StdLibIsLower, (wchar_t)MIN_,
202 (wchar_t)MAX_);
203 }
204
205 UPerfFunction* CharPerformanceTest::TestStdLibIsDigit()
206 {
207 return new StdLibCharPerfFunction(StdLibIsDigit, (wchar_t)MIN_,
208 (wchar_t)MAX_);
209 }
210
211 UPerfFunction* CharPerformanceTest::TestStdLibIsSpace()
212 {
213 return new StdLibCharPerfFunction(StdLibIsSpace, (wchar_t)MIN_,
214 (wchar_t)MAX_);
215 }
216
217 UPerfFunction* CharPerformanceTest::TestStdLibIsAlphaNumeric()
218 {
219 return new StdLibCharPerfFunction(StdLibIsAlphaNumeric, (wchar_t)MIN_,
220 (wchar_t)MAX_);
221 }
222
223 /**
224 * This test may be different since c lib has a type PUNCT and it is printable.
225 * iswgraph is not used for testing since it is a subset of iswprint with the
226 * exception of returning true for white spaces. no match found in icu4c.
227 */
228 UPerfFunction* CharPerformanceTest::TestStdLibIsPrint()
229 {
230 return new StdLibCharPerfFunction(StdLibIsPrint, (wchar_t)MIN_,
231 (wchar_t)MAX_);
232 }
233
234 UPerfFunction* CharPerformanceTest::TestStdLibIsControl()
235 {
236 return new StdLibCharPerfFunction(StdLibIsControl, (wchar_t)MIN_,
237 (wchar_t)MAX_);
238 }
239
240 UPerfFunction* CharPerformanceTest::TestStdLibToLower()
241 {
242 return new StdLibCharPerfFunction(StdLibToLower, (wchar_t)MIN_,
243 (wchar_t)MAX_);
244 }
245
246 UPerfFunction* CharPerformanceTest::TestStdLibToUpper()
247 {
248 return new StdLibCharPerfFunction(StdLibToUpper, (wchar_t)MIN_,
249 (wchar_t)MAX_);
250 }
251
252 UPerfFunction* CharPerformanceTest::TestStdLibIsWhiteSpace()
253 {
254 return new StdLibCharPerfFunction(StdLibIsWhiteSpace, (wchar_t)MIN_,
255 (wchar_t)MAX_);
256 }