]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/charperf/charperf.cpp
1 /********************************************************************
3 * Copyright (C) 2002-2016 IBM, Inc. All Rights Reserved.
5 ********************************************************************/
6 /*****************************************************************************
9 * Modification History:
11 * Syn Wee Quek First Version
12 ******************************************************************************
16 * This program tests character properties performance.
27 UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG
),
28 UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG
),
33 int main(int argc
, const char *argv
[])
35 UErrorCode status
= U_ZERO_ERROR
;
36 CharPerformanceTest
test(argc
, argv
, status
);
37 if (U_FAILURE(status
)){
40 if (test
.run() == FALSE
){
41 fprintf(stderr
, "FAILED: Tests could not be run please check the "
48 CharPerformanceTest::CharPerformanceTest(int32_t argc
, const char *argv
[],
50 : UPerfTest(argc
, argv
, status
)
52 if (status
== U_ILLEGAL_ARGUMENT_ERROR
){
53 fprintf(stderr
,gUsageString
, "charperf");
56 if (U_FAILURE(status
)){
57 fprintf(stderr
, "FAILED to create UPerfTest object. Error: %s\n",
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
;
68 _remainingArgc
= u_parseArgs(argc
, (char**)argv
,
69 UPRV_LENGTHOF(options
), options
);
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
80 printf("MAX_ size will be 0x%x\n", MAX_
);
81 if (options
[MIN_OPTION_
].doesOccur
) {
82 MIN_
= atoi(options
[MIN_OPTION_
].value
);
84 if (options
[MAX_OPTION_
].doesOccur
) {
85 MAX_
= atoi(options
[MAX_OPTION_
].value
);
89 CharPerformanceTest::~CharPerformanceTest()
93 UPerfFunction
* CharPerformanceTest::runIndexedTest(int32_t index
, UBool exec
,
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
);
127 UPerfFunction
* CharPerformanceTest::TestIsAlpha()
129 return new CharPerfFunction(isAlpha
, MIN_
, MAX_
);
132 UPerfFunction
* CharPerformanceTest::TestIsUpper()
134 return new CharPerfFunction(isUpper
, MIN_
, MAX_
);
137 UPerfFunction
* CharPerformanceTest::TestIsLower()
139 return new CharPerfFunction(isLower
, MIN_
, MAX_
);
142 UPerfFunction
* CharPerformanceTest::TestIsDigit()
144 return new CharPerfFunction(isDigit
, MIN_
, MAX_
);
147 UPerfFunction
* CharPerformanceTest::TestIsSpace()
149 return new CharPerfFunction(isSpace
, MIN_
, MAX_
);
152 UPerfFunction
* CharPerformanceTest::TestIsAlphaNumeric()
154 return new CharPerfFunction(isAlphaNumeric
, MIN_
, MAX_
);
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.
162 UPerfFunction
* CharPerformanceTest::TestIsPrint()
164 return new CharPerfFunction(isPrint
, MIN_
, MAX_
);
167 UPerfFunction
* CharPerformanceTest::TestIsControl()
169 return new CharPerfFunction(isControl
, MIN_
, MAX_
);
172 UPerfFunction
* CharPerformanceTest::TestToLower()
174 return new CharPerfFunction(toLower
, MIN_
, MAX_
);
177 UPerfFunction
* CharPerformanceTest::TestToUpper()
179 return new CharPerfFunction(toUpper
, MIN_
, MAX_
);
182 UPerfFunction
* CharPerformanceTest::TestIsWhiteSpace()
184 return new CharPerfFunction(isWhiteSpace
, MIN_
, MAX_
);
187 UPerfFunction
* CharPerformanceTest::TestStdLibIsAlpha()
189 return new StdLibCharPerfFunction(StdLibIsAlpha
, (wchar_t)MIN_
,
193 UPerfFunction
* CharPerformanceTest::TestStdLibIsUpper()
195 return new StdLibCharPerfFunction(StdLibIsUpper
, (wchar_t)MIN_
,
199 UPerfFunction
* CharPerformanceTest::TestStdLibIsLower()
201 return new StdLibCharPerfFunction(StdLibIsLower
, (wchar_t)MIN_
,
205 UPerfFunction
* CharPerformanceTest::TestStdLibIsDigit()
207 return new StdLibCharPerfFunction(StdLibIsDigit
, (wchar_t)MIN_
,
211 UPerfFunction
* CharPerformanceTest::TestStdLibIsSpace()
213 return new StdLibCharPerfFunction(StdLibIsSpace
, (wchar_t)MIN_
,
217 UPerfFunction
* CharPerformanceTest::TestStdLibIsAlphaNumeric()
219 return new StdLibCharPerfFunction(StdLibIsAlphaNumeric
, (wchar_t)MIN_
,
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.
228 UPerfFunction
* CharPerformanceTest::TestStdLibIsPrint()
230 return new StdLibCharPerfFunction(StdLibIsPrint
, (wchar_t)MIN_
,
234 UPerfFunction
* CharPerformanceTest::TestStdLibIsControl()
236 return new StdLibCharPerfFunction(StdLibIsControl
, (wchar_t)MIN_
,
240 UPerfFunction
* CharPerformanceTest::TestStdLibToLower()
242 return new StdLibCharPerfFunction(StdLibToLower
, (wchar_t)MIN_
,
246 UPerfFunction
* CharPerformanceTest::TestStdLibToUpper()
248 return new StdLibCharPerfFunction(StdLibToUpper
, (wchar_t)MIN_
,
252 UPerfFunction
* CharPerformanceTest::TestStdLibIsWhiteSpace()
254 return new StdLibCharPerfFunction(StdLibIsWhiteSpace
, (wchar_t)MIN_
,