]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/perf/normperf/normperf.h
ICU-6.2.21.tar.gz
[apple/icu.git] / icuSources / test / perf / normperf / normperf.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (c) 2002-2003, International Business Machines
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6**********************************************************************
7*/
8#ifndef _NORMPERF_H
9#define _NORMPERF_H
10
11#include "uperf.h"
12#include "unicode/unorm.h"
13#include "unicode/ustring.h"
14
15// Stubs for Windows API functions when building on UNIXes.
16//
17#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
18// do nothing
19#else
20#define _UNICODE
21typedef int DWORD;
22inline int FoldStringW(DWORD dwMapFlags, const UChar* lpSrcStr,int cchSrc, UChar* lpDestStr,int cchDest);
23#endif
24
25#define DEST_BUFFER_CAPACITY 6000
26typedef int32_t (*NormFn)(const UChar* src,int32_t srcLen, UChar* dest,int32_t dstLen, int32_t options, UErrorCode* status);
27typedef int32_t (*QuickCheckFn)(const UChar* src,int32_t srcLen, UNormalizationMode mode, int32_t options, UErrorCode* status);
28
29class QuickCheckPerfFunction : public UPerfFunction{
30private:
31 ULine* lines;
32 int32_t numLines;
33 QuickCheckFn fn;
34 UNormalizationMode mode;
35 int32_t retVal;
36 UBool uselen;
37 const UChar* src;
38 int32_t srcLen;
39 UBool line_mode;
40 int32_t options;
41
42public:
43 virtual void call(UErrorCode* status){
44 if(line_mode==TRUE){
45 if(uselen){
46 for(int32_t i = 0; i< numLines; i++){
47 retVal = (*fn)(lines[i].name,lines[i].len,mode, options, status);
48 }
49 }else{
50 for(int32_t i = 0; i< numLines; i++){
51 retVal = (*fn)(lines[i].name,-1,mode, options, status);
52 }
53 }
54 }else{
55 if(uselen){
56
57 retVal = (*fn)(src,srcLen,mode, options, status);
58 }else{
59 retVal = (*fn)(src,-1,mode, options, status);
60 }
61 }
62
63 }
64 virtual long getOperationsPerIteration(){
65 if(line_mode==TRUE){
66 int32_t totalChars=0;
67 for(int32_t i =0; i< numLines; i++){
68 totalChars+= lines[i].len;
69 }
70 return totalChars;
71 }else{
72 return srcLen;
73 }
74 }
75 QuickCheckPerfFunction(QuickCheckFn func, ULine* srcLines,int32_t srcNumLines, UNormalizationMode _mode, int32_t opts, UBool _uselen) : options(opts) {
76 fn = func;
77 lines = srcLines;
78 numLines = srcNumLines;
79 uselen = _uselen;
80 mode = _mode;
81 src = NULL;
82 srcLen = 0;
83 line_mode = TRUE;
84 }
85 QuickCheckPerfFunction(QuickCheckFn func, const UChar* source,int32_t sourceLen, UNormalizationMode _mode, int32_t opts, UBool _uselen) : options(opts) {
86 fn = func;
87 lines = NULL;
88 numLines = 0;
89 uselen = _uselen;
90 mode = _mode;
91 src = source;
92 srcLen = sourceLen;
93 line_mode = FALSE;
94 }
95};
96
97
98class NormPerfFunction : public UPerfFunction{
99private:
100 ULine* lines;
101 int32_t numLines;
102 UChar dest[DEST_BUFFER_CAPACITY];
103 UChar* pDest;
104 int32_t destLen;
105 NormFn fn;
106 int32_t retVal;
107 UBool uselen;
108 const UChar* src;
109 int32_t srcLen;
110 UBool line_mode;
111 int32_t options;
112
113public:
114 virtual void call(UErrorCode* status){
115 if(line_mode==TRUE){
116 if(uselen){
117 for(int32_t i = 0; i< numLines; i++){
118 retVal = (*fn)(lines[i].name,lines[i].len,pDest,destLen, options, status);
119 }
120 }else{
121 for(int32_t i = 0; i< numLines; i++){
122 retVal = (*fn)(lines[i].name,-1,pDest,destLen, options, status);
123 }
124 }
125 }else{
126 if(uselen){
127 retVal = (*fn)(src,srcLen,pDest,destLen, options, status);
128 }else{
129 retVal = (*fn)(src,-1,pDest,destLen, options, status);
130 }
131 }
132 }
133 virtual long getOperationsPerIteration(){
134 if(line_mode ==TRUE){
135 int32_t totalChars=0;
136 for(int32_t i =0; i< numLines; i++){
137 totalChars+= lines[i].len;
138 }
139 return totalChars;
140 }else{
141 return srcLen;
142 }
143 }
144 NormPerfFunction(NormFn func, int32_t opts, ULine* srcLines,int32_t srcNumLines,UBool _uselen) : options(opts) {
145 fn = func;
146 lines = srcLines;
147 numLines = srcNumLines;
148 uselen = _uselen;
149 destLen = DEST_BUFFER_CAPACITY;
150 pDest = dest;
151 src = NULL;
152 srcLen = 0;
153 line_mode = TRUE;
154 }
155 NormPerfFunction(NormFn func, int32_t opts, const UChar* source,int32_t sourceLen,UBool _uselen) : options(opts) {
156 fn = func;
157 lines = NULL;
158 numLines = 0;
159 uselen = _uselen;
160 destLen = sourceLen*3;
161 pDest = (UChar*) malloc(destLen * U_SIZEOF_UCHAR);
162 src = source;
163 srcLen = sourceLen;
164 line_mode = FALSE;
165 }
166 ~NormPerfFunction(){
167 if(dest != pDest){
168 free(pDest);
169 }
170 }
171};
172
173
174
175class NormalizerPerformanceTest : public UPerfTest{
176private:
177 ULine* NFDFileLines;
178 ULine* NFCFileLines;
179 UChar* NFDBuffer;
180 UChar* NFCBuffer;
181 UChar* origBuffer;
182 int32_t origBufferLen;
183 int32_t NFDBufferLen;
184 int32_t NFCBufferLen;
185 int32_t options;
186
187 void normalizeInput(ULine* dest,const UChar* src ,int32_t srcLen,UNormalizationMode mode, int32_t options);
188 UChar* normalizeInput(int32_t& len, const UChar* src ,int32_t srcLen,UNormalizationMode mode, int32_t options);
189
190public:
191
192 NormalizerPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status);
193 ~NormalizerPerformanceTest();
194 virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,const char* &name, char* par = NULL);
195 /* NFC performance */
196 UPerfFunction* TestICU_NFC_NFD_Text();
197 UPerfFunction* TestICU_NFC_NFC_Text();
198 UPerfFunction* TestICU_NFC_Orig_Text();
199
200 /* NFD performance */
201 UPerfFunction* TestICU_NFD_NFD_Text();
202 UPerfFunction* TestICU_NFD_NFC_Text();
203 UPerfFunction* TestICU_NFD_Orig_Text();
204
205 /* FCD performance */
206 UPerfFunction* TestICU_FCD_NFD_Text();
207 UPerfFunction* TestICU_FCD_NFC_Text();
208 UPerfFunction* TestICU_FCD_Orig_Text();
209
210 /*Win NFC performance */
211 UPerfFunction* TestWin_NFC_NFD_Text();
212 UPerfFunction* TestWin_NFC_NFC_Text();
213 UPerfFunction* TestWin_NFC_Orig_Text();
214
215 /* Win NFD performance */
216 UPerfFunction* TestWin_NFD_NFD_Text();
217 UPerfFunction* TestWin_NFD_NFC_Text();
218 UPerfFunction* TestWin_NFD_Orig_Text();
219
220 /* Quick check performance */
221 UPerfFunction* TestQC_NFC_NFD_Text();
222 UPerfFunction* TestQC_NFC_NFC_Text();
223 UPerfFunction* TestQC_NFC_Orig_Text();
224
225 UPerfFunction* TestQC_NFD_NFD_Text();
226 UPerfFunction* TestQC_NFD_NFC_Text();
227 UPerfFunction* TestQC_NFD_Orig_Text();
228
229 UPerfFunction* TestQC_FCD_NFD_Text();
230 UPerfFunction* TestQC_FCD_NFC_Text();
231 UPerfFunction* TestQC_FCD_Orig_Text();
232
233 /* IsNormalized performnace */
234 UPerfFunction* TestIsNormalized_NFC_NFD_Text();
235 UPerfFunction* TestIsNormalized_NFC_NFC_Text();
236 UPerfFunction* TestIsNormalized_NFC_Orig_Text();
237
238 UPerfFunction* TestIsNormalized_NFD_NFD_Text();
239 UPerfFunction* TestIsNormalized_NFD_NFC_Text();
240 UPerfFunction* TestIsNormalized_NFD_Orig_Text();
241
242 UPerfFunction* TestIsNormalized_FCD_NFD_Text();
243 UPerfFunction* TestIsNormalized_FCD_NFC_Text();
244 UPerfFunction* TestIsNormalized_FCD_Orig_Text();
245
246};
247
248//---------------------------------------------------------------------------------------
249// Platform / ICU version specific proto-types
250//---------------------------------------------------------------------------------------
251
252
253#if (U_ICU_VERSION_MAJOR_NUM > 1 ) || ((U_ICU_VERSION_MAJOR_NUM == 1 )&&(U_ICU_VERSION_MINOR_NUM > 8) && (U_ICU_VERSION_PATCHLEVEL_NUM >=1))
254
255int32_t ICUNormNFD(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
256 return unorm_normalize(src,srcLen,UNORM_NFD, options,dest,dstLen,status);
257}
258
259int32_t ICUNormNFC(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
260 return unorm_normalize(src,srcLen,UNORM_NFC, options,dest,dstLen,status);
261}
262
263int32_t ICUNormNFKD(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
264 return unorm_normalize(src,srcLen,UNORM_NFKD, options,dest,dstLen,status);
265}
266int32_t ICUNormNFKC(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
267 return unorm_normalize(src,srcLen,UNORM_NFKC, options,dest,dstLen,status);
268}
269
270int32_t ICUNormFCD(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
271 return unorm_normalize(src,srcLen,UNORM_FCD, options,dest,dstLen,status);
272}
273
274int32_t ICUQuickCheck(const UChar* src,int32_t srcLen, UNormalizationMode mode, int32_t options, UErrorCode* status){
275#if (U_ICU_VERSION_MAJOR_NUM > 2 ) || ((U_ICU_VERSION_MAJOR_NUM == 2 )&&(U_ICU_VERSION_MINOR_NUM >= 6))
276 return unorm_quickCheckWithOptions(src,srcLen,mode, options, status);
277#else
278 return unorm_quickCheck(src,srcLen,mode,status);
279#endif
280}
281int32_t ICUIsNormalized(const UChar* src,int32_t srcLen, UNormalizationMode mode, int32_t options, UErrorCode* status){
282 return unorm_isNormalized(src,srcLen,mode,status);
283}
284
285
286#else
287
288int32_t ICUNormNFD(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
289 return unorm_normalize(src,srcLen,UCOL_DECOMP_CAN, options,dest,dstLen,status);
290}
291
292int32_t ICUNormNFC(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
293 return unorm_normalize(src,srcLen,UCOL_COMPOSE_CAN, options,dest,dstLen,status);
294}
295
296int32_t ICUNormNFKD(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
297 return unorm_normalize(src,srcLen,UCOL_DECOMP_COMPAT, options,dest,dstLen,status);
298}
299int32_t ICUNormNFKC(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
300 return unorm_normalize(src,srcLen,UCOL_COMPOSE_COMPAT, options,dest,dstLen,status);
301}
302
303int32_t ICUNormFCD(const UChar* src, int32_t srcLen,UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
304 return unorm_normalize(src,srcLen,UNORM_FCD, options,dest,dstLen,status);
305}
306
307int32_t ICUQuickCheck(const UChar* src,int32_t srcLen, UNormalizationMode mode, int32_t options, UErrorCode* status){
308 return unorm_quickCheck(src,srcLen,mode,status);
309}
310
311int32_t ICUIsNormalized(const UChar* src,int32_t srcLen, UNormalizationMode mode, int32_t options, UErrorCode* status){
312 return 0;
313}
314#endif
315
316#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
317
318int32_t WinNormNFD(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
319 return FoldStringW(MAP_COMPOSITE,src,srcLen,dest,dstLen);
320}
321
322int32_t WinNormNFC(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
323 return FoldStringW(MAP_PRECOMPOSED,src,srcLen,dest,dstLen);
324}
325
326int32_t WinNormNFKD(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
327 return FoldStringW(MAP_COMPOSITE+MAP_FOLDCZONE,src,srcLen,dest,dstLen);
328}
329int32_t WinNormNFKC(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
330 return FoldStringW(MAP_FOLDCZONE,src,srcLen,dest,dstLen);
331}
332#else
333int32_t WinNormNFD(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
334 return 0 ;
335}
336
337int32_t WinNormNFC(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
338 return 0;
339}
340
341int32_t WinNormNFKD(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
342 return 0;
343}
344int32_t WinNormNFKC(const UChar* src, int32_t srcLen, UChar* dest, int32_t dstLen, int32_t options, UErrorCode* status) {
345 return 0;
346}
347#endif
348
349
350#endif // NORMPERF_H