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