summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/test/perf/charperf/charperf.h
blob: 8d892cb0a3adb6b4ab3e259500a083eadb0a3b66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
**********************************************************************
* Copyright (c) 2002-2005, International Business Machines
* Corporation and others.  All Rights Reserved.
**********************************************************************
**********************************************************************
*/
#ifndef _CHARPERF_H
#define _CHARPERF_H

#include "unicode/uchar.h"

#include "unicode/uperf.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>

typedef void (*CharPerfFn)(UChar32 ch);
typedef void (*StdLibCharPerfFn)(wchar_t ch);

class CharPerfFunction : public UPerfFunction
{
public:
	virtual void call(UErrorCode* status)
	{
		for (UChar32 i = MIN_; i < MAX_; i ++) {
			(*m_fn_)(i);
		}
	}

	virtual long getOperationsPerIteration()
	{
		return MAX_ - MIN_;
	}
	CharPerfFunction(CharPerfFn func, UChar32 min, UChar32 max)
	{
		m_fn_ = func;
		MIN_ = min;
		MAX_ = max;
	}   

private:
	CharPerfFn m_fn_;
	UChar32 MIN_;
	UChar32 MAX_;
}; 

class StdLibCharPerfFunction : public UPerfFunction
{
public:
	virtual void call(UErrorCode* status)
	{
		// note wchar_t is unsigned, it will revert to 0 once it reaches 
		// 65535
		for (wchar_t i = MIN_; i < MAX_; i ++) {
			(*m_fn_)(i);
		}
	}

	virtual long getOperationsPerIteration()
	{
		return MAX_ - MIN_;
	}

	StdLibCharPerfFunction(StdLibCharPerfFn func, wchar_t min, wchar_t max)
	{
		m_fn_ = func;			
		MIN_ = min;
		MAX_ = max;
	}   

	~StdLibCharPerfFunction()
	{			
	}

private:
	StdLibCharPerfFn m_fn_;
	wchar_t MIN_;
	wchar_t MAX_;
};

class CharPerformanceTest : public UPerfTest
{
public:
	CharPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status);
	~CharPerformanceTest();
	virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
		                                  const char *&name, 
										  char *par = NULL);     
	UPerfFunction* TestIsAlpha();
	UPerfFunction* TestIsUpper();
	UPerfFunction* TestIsLower();
	UPerfFunction* TestIsDigit();
	UPerfFunction* TestIsSpace();
	UPerfFunction* TestIsAlphaNumeric();
	UPerfFunction* TestIsPrint();
	UPerfFunction* TestIsControl();
	UPerfFunction* TestToLower();
	UPerfFunction* TestToUpper();
	UPerfFunction* TestIsWhiteSpace();
	UPerfFunction* TestStdLibIsAlpha();
	UPerfFunction* TestStdLibIsUpper();
	UPerfFunction* TestStdLibIsLower();
	UPerfFunction* TestStdLibIsDigit();
	UPerfFunction* TestStdLibIsSpace();
	UPerfFunction* TestStdLibIsAlphaNumeric();
	UPerfFunction* TestStdLibIsPrint();
	UPerfFunction* TestStdLibIsControl();
	UPerfFunction* TestStdLibToLower();
	UPerfFunction* TestStdLibToUpper();
	UPerfFunction* TestStdLibIsWhiteSpace();

private:
	UChar32 MIN_;
	UChar32 MAX_;
};

inline void isAlpha(UChar32 ch) 
{
    u_isalpha(ch);
}

inline void isUpper(UChar32 ch)
{
	u_isupper(ch);
}

inline void isLower(UChar32 ch)
{
	u_islower(ch);
}

inline void isDigit(UChar32 ch)
{
	u_isdigit(ch);
}

inline void isSpace(UChar32 ch)
{
	u_isspace(ch);
}

inline void isAlphaNumeric(UChar32 ch)
{
	u_isalnum(ch);
}

/**
 * This test may be different since c lib has a type PUNCT and it is printable.
 * iswgraph is not used for testing since it is a subset of iswprint with the
 * exception of returning true for white spaces. no match found in icu4c.
 */
inline void isPrint(UChar32 ch)
{
	u_isprint(ch);
}

inline void isControl(UChar32 ch)
{
	u_iscntrl(ch);
}

inline void toLower(UChar32 ch)
{
	u_tolower(ch);
}

inline void toUpper(UChar32 ch)
{
	u_toupper(ch);
}

inline void isWhiteSpace(UChar32 ch)
{
	u_isWhitespace(ch);
}

inline void StdLibIsAlpha(wchar_t ch)
{
	iswalpha(ch);
}

inline void StdLibIsUpper(wchar_t ch)
{
	iswupper(ch);
}

inline void StdLibIsLower(wchar_t ch)
{
	iswlower(ch);
}

inline void StdLibIsDigit(wchar_t ch)
{
	iswdigit(ch);
}

inline void StdLibIsSpace(wchar_t ch)
{
	iswspace(ch);
}

inline void StdLibIsAlphaNumeric(wchar_t ch)
{
	iswalnum(ch);
}

/**
 * This test may be different since c lib has a type PUNCT and it is printable.
 * iswgraph is not used for testing since it is a subset of iswprint with the
 * exception of returning true for white spaces. no match found in icu4c.
 */
inline void StdLibIsPrint(wchar_t ch)
{
	iswprint(ch);
}

inline void StdLibIsControl(wchar_t ch)
{
	iswcntrl(ch);
}

inline void StdLibToLower(wchar_t ch)
{
	towlower(ch);
}

inline void StdLibToUpper(wchar_t ch)
{
	towupper(ch);
}

inline void StdLibIsWhiteSpace(wchar_t ch)
{
	iswspace(ch);
}

#endif // CHARPERF_H