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