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