1 /***********************************************************************
2 * Copyright (C) 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 ***********************************************************************
5 ***********************************************************************
7 * Copyright (C) 2002-2016 IBM, Inc. All Rights Reserved.
9 ***********************************************************************/
10 /*****************************************************************************
13 * Modification History:
15 * Syn Wee Quek First Version
16 ******************************************************************************
20 * This program tests character properties performance.
31 UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG),
32 UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG),
37 int main(int argc, const char *argv[])
39 UErrorCode status = U_ZERO_ERROR;
40 CharPerformanceTest test(argc, argv, status);
41 if (U_FAILURE(status)){
44 if (test.run() == FALSE){
45 fprintf(stderr, "FAILED: Tests could not be run please check the "
52 CharPerformanceTest::CharPerformanceTest(int32_t argc, const char *argv[],
54 : UPerfTest(argc, argv, status)
56 if (status== U_ILLEGAL_ARGUMENT_ERROR){
57 fprintf(stderr,gUsageString, "charperf");
60 if (U_FAILURE(status)){
61 fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n",
66 if (_remainingArgc < 0) {
67 // that means there are some -names not matched in the super class
68 // first tag is always skipped in u_parseArgs
69 int size = - _remainingArgc;
72 _remainingArgc = u_parseArgs(argc, (char**)argv,
73 UPRV_LENGTHOF(options), options);
76 if (sizeof(wchar_t) > 2) {
77 // for stdlibs like glibc that supports 32 bits wchar
78 // we test for the whole unicode character set by default
84 printf("MAX_ size will be 0x%x\n", MAX_);
85 if (options[MIN_OPTION_].doesOccur) {
86 MIN_ = atoi(options[MIN_OPTION_].value);
88 if (options[MAX_OPTION_].doesOccur) {
89 MAX_ = atoi(options[MAX_OPTION_].value);
93 CharPerformanceTest::~CharPerformanceTest()
97 UPerfFunction* CharPerformanceTest::runIndexedTest(int32_t index, UBool exec,
102 TESTCASE(0, TestIsAlpha);
103 TESTCASE(1, TestIsUpper);
104 TESTCASE(2, TestIsLower);
105 TESTCASE(3, TestIsDigit);
106 TESTCASE(4, TestIsSpace);
107 TESTCASE(5, TestIsAlphaNumeric);
108 TESTCASE(6, TestIsPrint);
109 TESTCASE(7, TestIsControl);
110 TESTCASE(8, TestToLower);
111 TESTCASE(9, TestToUpper);
112 TESTCASE(10, TestIsWhiteSpace);
113 TESTCASE(11, TestStdLibIsAlpha);
114 TESTCASE(12, TestStdLibIsUpper);
115 TESTCASE(13, TestStdLibIsLower);
116 TESTCASE(14, TestStdLibIsDigit);
117 TESTCASE(15, TestStdLibIsSpace);
118 TESTCASE(16, TestStdLibIsAlphaNumeric);
119 TESTCASE(17, TestStdLibIsPrint);
120 TESTCASE(18, TestStdLibIsControl);
121 TESTCASE(19, TestStdLibToLower);
122 TESTCASE(20, TestStdLibToUpper);
123 TESTCASE(21, TestStdLibIsWhiteSpace);
131 UPerfFunction* CharPerformanceTest::TestIsAlpha()
133 return new CharPerfFunction(isAlpha, MIN_, MAX_);
136 UPerfFunction* CharPerformanceTest::TestIsUpper()
138 return new CharPerfFunction(isUpper, MIN_, MAX_);
141 UPerfFunction* CharPerformanceTest::TestIsLower()
143 return new CharPerfFunction(isLower, MIN_, MAX_);
146 UPerfFunction* CharPerformanceTest::TestIsDigit()
148 return new CharPerfFunction(isDigit, MIN_, MAX_);
151 UPerfFunction* CharPerformanceTest::TestIsSpace()
153 return new CharPerfFunction(isSpace, MIN_, MAX_);
156 UPerfFunction* CharPerformanceTest::TestIsAlphaNumeric()
158 return new CharPerfFunction(isAlphaNumeric, MIN_, MAX_);
162 * This test may be different since c lib has a type PUNCT and it is printable.
163 * iswgraph is not used for testing since it is a subset of iswprint with the
164 * exception of returning true for white spaces. no match found in icu4c.
166 UPerfFunction* CharPerformanceTest::TestIsPrint()
168 return new CharPerfFunction(isPrint, MIN_, MAX_);
171 UPerfFunction* CharPerformanceTest::TestIsControl()
173 return new CharPerfFunction(isControl, MIN_, MAX_);
176 UPerfFunction* CharPerformanceTest::TestToLower()
178 return new CharPerfFunction(toLower, MIN_, MAX_);
181 UPerfFunction* CharPerformanceTest::TestToUpper()
183 return new CharPerfFunction(toUpper, MIN_, MAX_);
186 UPerfFunction* CharPerformanceTest::TestIsWhiteSpace()
188 return new CharPerfFunction(isWhiteSpace, MIN_, MAX_);
191 UPerfFunction* CharPerformanceTest::TestStdLibIsAlpha()
193 return new StdLibCharPerfFunction(StdLibIsAlpha, (wchar_t)MIN_,
197 UPerfFunction* CharPerformanceTest::TestStdLibIsUpper()
199 return new StdLibCharPerfFunction(StdLibIsUpper, (wchar_t)MIN_,
203 UPerfFunction* CharPerformanceTest::TestStdLibIsLower()
205 return new StdLibCharPerfFunction(StdLibIsLower, (wchar_t)MIN_,
209 UPerfFunction* CharPerformanceTest::TestStdLibIsDigit()
211 return new StdLibCharPerfFunction(StdLibIsDigit, (wchar_t)MIN_,
215 UPerfFunction* CharPerformanceTest::TestStdLibIsSpace()
217 return new StdLibCharPerfFunction(StdLibIsSpace, (wchar_t)MIN_,
221 UPerfFunction* CharPerformanceTest::TestStdLibIsAlphaNumeric()
223 return new StdLibCharPerfFunction(StdLibIsAlphaNumeric, (wchar_t)MIN_,
228 * This test may be different since c lib has a type PUNCT and it is printable.
229 * iswgraph is not used for testing since it is a subset of iswprint with the
230 * exception of returning true for white spaces. no match found in icu4c.
232 UPerfFunction* CharPerformanceTest::TestStdLibIsPrint()
234 return new StdLibCharPerfFunction(StdLibIsPrint, (wchar_t)MIN_,
238 UPerfFunction* CharPerformanceTest::TestStdLibIsControl()
240 return new StdLibCharPerfFunction(StdLibIsControl, (wchar_t)MIN_,
244 UPerfFunction* CharPerformanceTest::TestStdLibToLower()
246 return new StdLibCharPerfFunction(StdLibToLower, (wchar_t)MIN_,
250 UPerfFunction* CharPerformanceTest::TestStdLibToUpper()
252 return new StdLibCharPerfFunction(StdLibToUpper, (wchar_t)MIN_,
256 UPerfFunction* CharPerformanceTest::TestStdLibIsWhiteSpace()
258 return new StdLibCharPerfFunction(StdLibIsWhiteSpace, (wchar_t)MIN_,