]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/perf/charperf/charperf.h
ICU-551.24.tar.gz
[apple/icu.git] / icuSources / test / perf / charperf / charperf.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
73c04bcf 3* Copyright (c) 2002-2006, International Business Machines
b75a7d8f
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6**********************************************************************
7*/
8#ifndef _CHARPERF_H
9#define _CHARPERF_H
10
b75a7d8f 11#include "unicode/uchar.h"
73c04bcf
A
12
13#include "unicode/uperf.h"
b75a7d8f
A
14#include <stdlib.h>
15#include <stdio.h>
16#include <wchar.h>
374ca955 17#include <wctype.h>
b75a7d8f
A
18
19typedef void (*CharPerfFn)(UChar32 ch);
20typedef void (*StdLibCharPerfFn)(wchar_t ch);
21
22class CharPerfFunction : public UPerfFunction
23{
24public:
73c04bcf
A
25 virtual void call(UErrorCode* status)
26 {
27 for (UChar32 i = MIN_; i < MAX_; i ++) {
28 (*m_fn_)(i);
29 }
30 }
31
32 virtual long getOperationsPerIteration()
33 {
34 return MAX_ - MIN_;
35 }
36 CharPerfFunction(CharPerfFn func, UChar32 min, UChar32 max)
37 {
38 m_fn_ = func;
39 MIN_ = min;
40 MAX_ = max;
41 }
b75a7d8f
A
42
43private:
73c04bcf
A
44 CharPerfFn m_fn_;
45 UChar32 MIN_;
46 UChar32 MAX_;
b75a7d8f
A
47};
48
49class StdLibCharPerfFunction : public UPerfFunction
50{
51public:
73c04bcf
A
52 virtual void call(UErrorCode* status)
53 {
54 // note wchar_t is unsigned, it will revert to 0 once it reaches
55 // 65535
56 for (wchar_t i = MIN_; i < MAX_; i ++) {
57 (*m_fn_)(i);
58 }
59 }
60
61 virtual long getOperationsPerIteration()
62 {
63 return MAX_ - MIN_;
64 }
65
66 StdLibCharPerfFunction(StdLibCharPerfFn func, wchar_t min, wchar_t max)
67 {
68 m_fn_ = func;
69 MIN_ = min;
70 MAX_ = max;
71 }
72
73 ~StdLibCharPerfFunction()
74 {
75 }
b75a7d8f
A
76
77private:
73c04bcf
A
78 StdLibCharPerfFn m_fn_;
79 wchar_t MIN_;
80 wchar_t MAX_;
b75a7d8f
A
81};
82
83class CharPerformanceTest : public UPerfTest
84{
85public:
73c04bcf
A
86 CharPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status);
87 ~CharPerformanceTest();
88 virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
89 const char *&name,
90 char *par = NULL);
91 UPerfFunction* TestIsAlpha();
92 UPerfFunction* TestIsUpper();
93 UPerfFunction* TestIsLower();
94 UPerfFunction* TestIsDigit();
95 UPerfFunction* TestIsSpace();
96 UPerfFunction* TestIsAlphaNumeric();
97 UPerfFunction* TestIsPrint();
98 UPerfFunction* TestIsControl();
99 UPerfFunction* TestToLower();
100 UPerfFunction* TestToUpper();
101 UPerfFunction* TestIsWhiteSpace();
102 UPerfFunction* TestStdLibIsAlpha();
103 UPerfFunction* TestStdLibIsUpper();
104 UPerfFunction* TestStdLibIsLower();
105 UPerfFunction* TestStdLibIsDigit();
106 UPerfFunction* TestStdLibIsSpace();
107 UPerfFunction* TestStdLibIsAlphaNumeric();
108 UPerfFunction* TestStdLibIsPrint();
109 UPerfFunction* TestStdLibIsControl();
110 UPerfFunction* TestStdLibToLower();
111 UPerfFunction* TestStdLibToUpper();
112 UPerfFunction* TestStdLibIsWhiteSpace();
b75a7d8f
A
113
114private:
73c04bcf
A
115 UChar32 MIN_;
116 UChar32 MAX_;
b75a7d8f
A
117};
118
119inline void isAlpha(UChar32 ch)
120{
121 u_isalpha(ch);
122}
123
124inline void isUpper(UChar32 ch)
125{
73c04bcf 126 u_isupper(ch);
b75a7d8f
A
127}
128
129inline void isLower(UChar32 ch)
130{
73c04bcf 131 u_islower(ch);
b75a7d8f
A
132}
133
134inline void isDigit(UChar32 ch)
135{
73c04bcf 136 u_isdigit(ch);
b75a7d8f
A
137}
138
139inline void isSpace(UChar32 ch)
140{
73c04bcf 141 u_isspace(ch);
b75a7d8f
A
142}
143
144inline void isAlphaNumeric(UChar32 ch)
145{
73c04bcf 146 u_isalnum(ch);
b75a7d8f
A
147}
148
149/**
73c04bcf
A
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*/
b75a7d8f
A
154inline void isPrint(UChar32 ch)
155{
73c04bcf 156 u_isprint(ch);
b75a7d8f
A
157}
158
159inline void isControl(UChar32 ch)
160{
73c04bcf 161 u_iscntrl(ch);
b75a7d8f
A
162}
163
164inline void toLower(UChar32 ch)
165{
73c04bcf 166 u_tolower(ch);
b75a7d8f
A
167}
168
169inline void toUpper(UChar32 ch)
170{
73c04bcf 171 u_toupper(ch);
b75a7d8f
A
172}
173
174inline void isWhiteSpace(UChar32 ch)
175{
73c04bcf 176 u_isWhitespace(ch);
b75a7d8f
A
177}
178
179inline void StdLibIsAlpha(wchar_t ch)
180{
73c04bcf 181 iswalpha(ch);
b75a7d8f
A
182}
183
184inline void StdLibIsUpper(wchar_t ch)
185{
73c04bcf 186 iswupper(ch);
b75a7d8f
A
187}
188
189inline void StdLibIsLower(wchar_t ch)
190{
73c04bcf 191 iswlower(ch);
b75a7d8f
A
192}
193
194inline void StdLibIsDigit(wchar_t ch)
195{
73c04bcf 196 iswdigit(ch);
b75a7d8f
A
197}
198
199inline void StdLibIsSpace(wchar_t ch)
200{
73c04bcf 201 iswspace(ch);
b75a7d8f
A
202}
203
204inline void StdLibIsAlphaNumeric(wchar_t ch)
205{
73c04bcf 206 iswalnum(ch);
b75a7d8f
A
207}
208
209/**
73c04bcf
A
210* This test may be different since c lib has a type PUNCT and it is printable.
211* iswgraph is not used for testing since it is a subset of iswprint with the
212* exception of returning true for white spaces. no match found in icu4c.
213*/
b75a7d8f
A
214inline void StdLibIsPrint(wchar_t ch)
215{
73c04bcf 216 iswprint(ch);
b75a7d8f
A
217}
218
219inline void StdLibIsControl(wchar_t ch)
220{
73c04bcf 221 iswcntrl(ch);
b75a7d8f
A
222}
223
224inline void StdLibToLower(wchar_t ch)
225{
73c04bcf 226 towlower(ch);
b75a7d8f
A
227}
228
229inline void StdLibToUpper(wchar_t ch)
230{
73c04bcf 231 towupper(ch);
b75a7d8f
A
232}
233
234inline void StdLibIsWhiteSpace(wchar_t ch)
235{
73c04bcf 236 iswspace(ch);
b75a7d8f
A
237}
238
374ca955 239#endif // CHARPERF_H