]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/charperf/charperf.cpp
1 /********************************************************************
3 * Copyright (C) 2002-2003 IBM, Inc. All Rights Reserved.
5 ********************************************************************/
6 /*****************************************************************************
9 * Modification History:
11 * Syn Wee Quek First Version
12 ******************************************************************************
16 * This program tests character properties performance.
26 UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG
),
27 UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG
),
32 int main(int argc
, const char *argv
[])
34 UErrorCode status
= U_ZERO_ERROR
;
35 CharPerformanceTest
test(argc
, argv
, status
);
36 if (U_FAILURE(status
)){
39 if (test
.run() == FALSE
){
40 fprintf(stderr
, "FAILED: Tests could not be run please check the "
47 CharPerformanceTest::CharPerformanceTest(int32_t argc
, const char *argv
[],
49 : UPerfTest(argc
, argv
, status
)
51 if (status
== U_ILLEGAL_ARGUMENT_ERROR
){
52 fprintf(stderr
,gUsageString
, "charperf");
55 if (U_FAILURE(status
)){
56 fprintf(stderr
, "FAILED to create UPerfTest object. Error: %s\n",
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
;
67 _remainingArgc
= u_parseArgs(argc
, (char**)argv
,
68 (int32_t)(sizeof(options
)/sizeof(options
[0])), options
);
71 if (sizeof(wchar_t) > 2) {
72 // for stdlibs like glibc that supports 32 bits wchar
73 // we test for the whole unicode character set by default
79 printf("MAX_ size will be 0x%x\n", MAX_
);
80 if (options
[MIN_OPTION_
].doesOccur
) {
81 MIN_
= atoi(options
[MIN_OPTION_
].value
);
83 if (options
[MAX_OPTION_
].doesOccur
) {
84 MAX_
= atoi(options
[MAX_OPTION_
].value
);
88 CharPerformanceTest::~CharPerformanceTest()
92 UPerfFunction
* CharPerformanceTest::runIndexedTest(int32_t index
, UBool exec
,
97 TESTCASE(0, TestIsAlpha
);
98 TESTCASE(1, TestIsUpper
);
99 TESTCASE(2, TestIsLower
);
100 TESTCASE(3, TestIsDigit
);
101 TESTCASE(4, TestIsSpace
);
102 TESTCASE(5, TestIsAlphaNumeric
);
103 TESTCASE(6, TestIsPrint
);
104 TESTCASE(7, TestIsControl
);
105 TESTCASE(8, TestToLower
);
106 TESTCASE(9, TestToUpper
);
107 TESTCASE(10, TestIsWhiteSpace
);
108 TESTCASE(11, TestStdLibIsAlpha
);
109 TESTCASE(12, TestStdLibIsUpper
);
110 TESTCASE(13, TestStdLibIsLower
);
111 TESTCASE(14, TestStdLibIsDigit
);
112 TESTCASE(15, TestStdLibIsSpace
);
113 TESTCASE(16, TestStdLibIsAlphaNumeric
);
114 TESTCASE(17, TestStdLibIsPrint
);
115 TESTCASE(18, TestStdLibIsControl
);
116 TESTCASE(19, TestStdLibToLower
);
117 TESTCASE(20, TestStdLibToUpper
);
118 TESTCASE(21, TestStdLibIsWhiteSpace
);
126 UPerfFunction
* CharPerformanceTest::TestIsAlpha()
128 return new CharPerfFunction(isAlpha
, MIN_
, MAX_
);
131 UPerfFunction
* CharPerformanceTest::TestIsUpper()
133 return new CharPerfFunction(isUpper
, MIN_
, MAX_
);
136 UPerfFunction
* CharPerformanceTest::TestIsLower()
138 return new CharPerfFunction(isLower
, MIN_
, MAX_
);
141 UPerfFunction
* CharPerformanceTest::TestIsDigit()
143 return new CharPerfFunction(isDigit
, MIN_
, MAX_
);
146 UPerfFunction
* CharPerformanceTest::TestIsSpace()
148 return new CharPerfFunction(isSpace
, MIN_
, MAX_
);
151 UPerfFunction
* CharPerformanceTest::TestIsAlphaNumeric()
153 return new CharPerfFunction(isAlphaNumeric
, MIN_
, MAX_
);
157 * This test may be different since c lib has a type PUNCT and it is printable.
158 * iswgraph is not used for testing since it is a subset of iswprint with the
159 * exception of returning true for white spaces. no match found in icu4c.
161 UPerfFunction
* CharPerformanceTest::TestIsPrint()
163 return new CharPerfFunction(isPrint
, MIN_
, MAX_
);
166 UPerfFunction
* CharPerformanceTest::TestIsControl()
168 return new CharPerfFunction(isControl
, MIN_
, MAX_
);
171 UPerfFunction
* CharPerformanceTest::TestToLower()
173 return new CharPerfFunction(toLower
, MIN_
, MAX_
);
176 UPerfFunction
* CharPerformanceTest::TestToUpper()
178 return new CharPerfFunction(toUpper
, MIN_
, MAX_
);
181 UPerfFunction
* CharPerformanceTest::TestIsWhiteSpace()
183 return new CharPerfFunction(isWhiteSpace
, MIN_
, MAX_
);
186 UPerfFunction
* CharPerformanceTest::TestStdLibIsAlpha()
188 return new StdLibCharPerfFunction(StdLibIsAlpha
, (wchar_t)MIN_
,
192 UPerfFunction
* CharPerformanceTest::TestStdLibIsUpper()
194 return new StdLibCharPerfFunction(StdLibIsUpper
, (wchar_t)MIN_
,
198 UPerfFunction
* CharPerformanceTest::TestStdLibIsLower()
200 return new StdLibCharPerfFunction(StdLibIsLower
, (wchar_t)MIN_
,
204 UPerfFunction
* CharPerformanceTest::TestStdLibIsDigit()
206 return new StdLibCharPerfFunction(StdLibIsDigit
, (wchar_t)MIN_
,
210 UPerfFunction
* CharPerformanceTest::TestStdLibIsSpace()
212 return new StdLibCharPerfFunction(StdLibIsSpace
, (wchar_t)MIN_
,
216 UPerfFunction
* CharPerformanceTest::TestStdLibIsAlphaNumeric()
218 return new StdLibCharPerfFunction(StdLibIsAlphaNumeric
, (wchar_t)MIN_
,
223 * This test may be different since c lib has a type PUNCT and it is printable.
224 * iswgraph is not used for testing since it is a subset of iswprint with the
225 * exception of returning true for white spaces. no match found in icu4c.
227 UPerfFunction
* CharPerformanceTest::TestStdLibIsPrint()
229 return new StdLibCharPerfFunction(StdLibIsPrint
, (wchar_t)MIN_
,
233 UPerfFunction
* CharPerformanceTest::TestStdLibIsControl()
235 return new StdLibCharPerfFunction(StdLibIsControl
, (wchar_t)MIN_
,
239 UPerfFunction
* CharPerformanceTest::TestStdLibToLower()
241 return new StdLibCharPerfFunction(StdLibToLower
, (wchar_t)MIN_
,
245 UPerfFunction
* CharPerformanceTest::TestStdLibToUpper()
247 return new StdLibCharPerfFunction(StdLibToUpper
, (wchar_t)MIN_
,
251 UPerfFunction
* CharPerformanceTest::TestStdLibIsWhiteSpace()
253 return new StdLibCharPerfFunction(StdLibIsWhiteSpace
, (wchar_t)MIN_
,