]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/perf/charperf/charperf.cpp
ICU-531.48.tar.gz
[apple/icu.git] / icuSources / test / perf / charperf / charperf.cpp
CommitLineData
b75a7d8f
A
1/********************************************************************
2 * COPYRIGHT:
73c04bcf 3 * Copyright (C) 2002-2006 IBM, Inc. All Rights Reserved.
b75a7d8f
A
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
25UOption options[] = {
73c04bcf
A
26 UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG),
27 UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG),
28};
b75a7d8f
A
29int MIN_OPTION_ = 0;
30int MAX_OPTION_ = 1;
31
32int main(int argc, const char *argv[])
33{
34 UErrorCode status = U_ZERO_ERROR;
35 CharPerformanceTest test(argc, argv, status);
73c04bcf 36 if (U_FAILURE(status)){
b75a7d8f
A
37 return status;
38 }
39 if (test.run() == FALSE){
40 fprintf(stderr, "FAILED: Tests could not be run please check the "
73c04bcf 41 "arguments.\n");
b75a7d8f
A
42 return -1;
43 }
44 return 0;
45}
46
47CharPerformanceTest::CharPerformanceTest(int32_t argc, const char *argv[],
73c04bcf
A
48 UErrorCode &status)
49 : UPerfTest(argc, argv, status)
b75a7d8f 50{
73c04bcf
A
51 if (status== U_ILLEGAL_ARGUMENT_ERROR){
52 fprintf(stderr,gUsageString, "charperf");
53 return;
b75a7d8f
A
54 }
55 if (U_FAILURE(status)){
56 fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n",
73c04bcf 57 u_errorName(status));
b75a7d8f
A
58 return;
59 }
60
73c04bcf
A
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;
374ca955
A
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
74 MAX_ = 0x10ffff;
75 }
76 else {
77 MAX_ = 0xffff;
78 }
79 printf("MAX_ size will be 0x%x\n", MAX_);
73c04bcf
A
80 if (options[MIN_OPTION_].doesOccur) {
81 MIN_ = atoi(options[MIN_OPTION_].value);
82 }
83 if (options[MAX_OPTION_].doesOccur) {
84 MAX_ = atoi(options[MAX_OPTION_].value);
85 }
b75a7d8f
A
86}
87
88CharPerformanceTest::~CharPerformanceTest()
89{
90}
91
92UPerfFunction* CharPerformanceTest::runIndexedTest(int32_t index, UBool exec,
73c04bcf
A
93 const char *&name,
94 char* par)
b75a7d8f
A
95{
96 switch (index) {
97 TESTCASE(0, TestIsAlpha);
73c04bcf
A
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);
b75a7d8f
A
119 default:
120 name = "";
121 return NULL;
122 }
123 return NULL;
124}
125
126UPerfFunction* CharPerformanceTest::TestIsAlpha()
127{
73c04bcf 128 return new CharPerfFunction(isAlpha, MIN_, MAX_);
b75a7d8f
A
129}
130
131UPerfFunction* CharPerformanceTest::TestIsUpper()
132{
73c04bcf 133 return new CharPerfFunction(isUpper, MIN_, MAX_);
b75a7d8f
A
134}
135
136UPerfFunction* CharPerformanceTest::TestIsLower()
137{
73c04bcf 138 return new CharPerfFunction(isLower, MIN_, MAX_);
b75a7d8f
A
139}
140
141UPerfFunction* CharPerformanceTest::TestIsDigit()
142{
73c04bcf 143 return new CharPerfFunction(isDigit, MIN_, MAX_);
b75a7d8f
A
144}
145
146UPerfFunction* CharPerformanceTest::TestIsSpace()
147{
73c04bcf 148 return new CharPerfFunction(isSpace, MIN_, MAX_);
b75a7d8f
A
149}
150
151UPerfFunction* CharPerformanceTest::TestIsAlphaNumeric()
152{
73c04bcf 153 return new CharPerfFunction(isAlphaNumeric, MIN_, MAX_);
b75a7d8f
A
154}
155
156/**
73c04bcf
A
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.
160*/
b75a7d8f
A
161UPerfFunction* CharPerformanceTest::TestIsPrint()
162{
73c04bcf 163 return new CharPerfFunction(isPrint, MIN_, MAX_);
b75a7d8f
A
164}
165
166UPerfFunction* CharPerformanceTest::TestIsControl()
167{
73c04bcf 168 return new CharPerfFunction(isControl, MIN_, MAX_);
b75a7d8f
A
169}
170
171UPerfFunction* CharPerformanceTest::TestToLower()
172{
73c04bcf 173 return new CharPerfFunction(toLower, MIN_, MAX_);
b75a7d8f
A
174}
175
176UPerfFunction* CharPerformanceTest::TestToUpper()
177{
73c04bcf 178 return new CharPerfFunction(toUpper, MIN_, MAX_);
b75a7d8f
A
179}
180
181UPerfFunction* CharPerformanceTest::TestIsWhiteSpace()
182{
73c04bcf 183 return new CharPerfFunction(isWhiteSpace, MIN_, MAX_);
b75a7d8f
A
184}
185
186UPerfFunction* CharPerformanceTest::TestStdLibIsAlpha()
187{
73c04bcf
A
188 return new StdLibCharPerfFunction(StdLibIsAlpha, (wchar_t)MIN_,
189 (wchar_t)MAX_);
b75a7d8f
A
190}
191
192UPerfFunction* CharPerformanceTest::TestStdLibIsUpper()
193{
73c04bcf
A
194 return new StdLibCharPerfFunction(StdLibIsUpper, (wchar_t)MIN_,
195 (wchar_t)MAX_);
b75a7d8f
A
196}
197
198UPerfFunction* CharPerformanceTest::TestStdLibIsLower()
199{
73c04bcf
A
200 return new StdLibCharPerfFunction(StdLibIsLower, (wchar_t)MIN_,
201 (wchar_t)MAX_);
b75a7d8f
A
202}
203
204UPerfFunction* CharPerformanceTest::TestStdLibIsDigit()
205{
73c04bcf
A
206 return new StdLibCharPerfFunction(StdLibIsDigit, (wchar_t)MIN_,
207 (wchar_t)MAX_);
b75a7d8f
A
208}
209
210UPerfFunction* CharPerformanceTest::TestStdLibIsSpace()
211{
73c04bcf
A
212 return new StdLibCharPerfFunction(StdLibIsSpace, (wchar_t)MIN_,
213 (wchar_t)MAX_);
b75a7d8f
A
214}
215
216UPerfFunction* CharPerformanceTest::TestStdLibIsAlphaNumeric()
217{
73c04bcf
A
218 return new StdLibCharPerfFunction(StdLibIsAlphaNumeric, (wchar_t)MIN_,
219 (wchar_t)MAX_);
b75a7d8f
A
220}
221
222/**
73c04bcf
A
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.
226*/
b75a7d8f
A
227UPerfFunction* CharPerformanceTest::TestStdLibIsPrint()
228{
73c04bcf
A
229 return new StdLibCharPerfFunction(StdLibIsPrint, (wchar_t)MIN_,
230 (wchar_t)MAX_);
b75a7d8f
A
231}
232
233UPerfFunction* CharPerformanceTest::TestStdLibIsControl()
234{
73c04bcf
A
235 return new StdLibCharPerfFunction(StdLibIsControl, (wchar_t)MIN_,
236 (wchar_t)MAX_);
b75a7d8f
A
237}
238
239UPerfFunction* CharPerformanceTest::TestStdLibToLower()
240{
73c04bcf
A
241 return new StdLibCharPerfFunction(StdLibToLower, (wchar_t)MIN_,
242 (wchar_t)MAX_);
b75a7d8f
A
243}
244
245UPerfFunction* CharPerformanceTest::TestStdLibToUpper()
246{
73c04bcf
A
247 return new StdLibCharPerfFunction(StdLibToUpper, (wchar_t)MIN_,
248 (wchar_t)MAX_);
b75a7d8f
A
249}
250
251UPerfFunction* CharPerformanceTest::TestStdLibIsWhiteSpace()
252{
73c04bcf
A
253 return new StdLibCharPerfFunction(StdLibIsWhiteSpace, (wchar_t)MIN_,
254 (wchar_t)MAX_);
b75a7d8f 255}