]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/perf/normperf/normperf.cpp
ICU-6.2.21.tar.gz
[apple/icu.git] / icuSources / test / perf / normperf / normperf.cpp
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
3* Copyright (c) 2002-2003, International Business Machines
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6**********************************************************************
7*/
8/**
9 * This Program tests the performance of ICU's Normalization engine against Windows
10 * to run it use the command like
11 *
12 * c:\normperf.exe -s C:\work\ICUCupertinoRep\icu4c\collation-perf-data -i 10 -p 15 -f TestNames_Asian.txt -u -e UTF-8 -l
13 */
14#include "normperf.h"
15
16#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
17
18UPerfFunction* NormalizerPerformanceTest::runIndexedTest(int32_t index, UBool exec,const char* &name, char* par) {
19 switch (index) {
20 TESTCASE(0,TestICU_NFC_NFD_Text);
21 TESTCASE(1,TestICU_NFC_NFC_Text);
22 TESTCASE(2,TestICU_NFC_Orig_Text);
23
24 TESTCASE(3,TestICU_NFD_NFD_Text);
25 TESTCASE(4,TestICU_NFD_NFC_Text);
26 TESTCASE(5,TestICU_NFD_Orig_Text);
27
28 TESTCASE(6,TestICU_FCD_NFD_Text);
29 TESTCASE(7,TestICU_FCD_NFC_Text);
30 TESTCASE(8,TestICU_FCD_Orig_Text);
31
32 TESTCASE(9,TestWin_NFC_NFD_Text);
33 TESTCASE(10,TestWin_NFC_NFC_Text);
34 TESTCASE(11,TestWin_NFC_Orig_Text);
35
36 TESTCASE(12,TestWin_NFD_NFD_Text);
37 TESTCASE(13,TestWin_NFD_NFC_Text);
38 TESTCASE(14,TestWin_NFD_Orig_Text);
39
40 TESTCASE(15,TestQC_NFC_NFD_Text);
41 TESTCASE(16,TestQC_NFC_NFC_Text);
42 TESTCASE(17,TestQC_NFC_Orig_Text);
43
44 TESTCASE(18,TestQC_NFD_NFD_Text);
45 TESTCASE(19,TestQC_NFD_NFC_Text);
46 TESTCASE(20,TestQC_NFD_Orig_Text);
47
48 TESTCASE(21,TestQC_FCD_NFD_Text);
49 TESTCASE(22,TestQC_FCD_NFC_Text);
50 TESTCASE(23,TestQC_FCD_Orig_Text);
51
52 TESTCASE(24,TestIsNormalized_NFC_NFD_Text);
53 TESTCASE(25,TestIsNormalized_NFC_NFC_Text);
54 TESTCASE(26,TestIsNormalized_NFC_Orig_Text);
55
56 TESTCASE(27,TestIsNormalized_NFD_NFD_Text);
57 TESTCASE(28,TestIsNormalized_NFD_NFC_Text);
58 TESTCASE(29,TestIsNormalized_NFD_Orig_Text);
59
60 TESTCASE(30,TestIsNormalized_FCD_NFD_Text);
61 TESTCASE(31,TestIsNormalized_FCD_NFC_Text);
62 TESTCASE(32,TestIsNormalized_FCD_Orig_Text);
63
64 default:
65 name = "";
66 return NULL;
67 }
68 return NULL;
69
70}
71
72void NormalizerPerformanceTest::normalizeInput(ULine* dest,const UChar* src ,int32_t srcLen,UNormalizationMode mode, int32_t options){
73 int32_t reqLen = 0;
74 UErrorCode status = U_ZERO_ERROR;
75 for(;;){
76 /* pure pre-flight */
77 reqLen=unorm_normalize(src,srcLen,mode, options,NULL,0,&status);
78 if(status==U_BUFFER_OVERFLOW_ERROR){
79 status=U_ZERO_ERROR;
80 dest->name = new UChar[reqLen+1];
81 reqLen= unorm_normalize(src,srcLen,mode, options,dest->name,reqLen+1,&status);
82 dest->len=reqLen;
83 break;
84 }else if(U_FAILURE(status)){
85 printf("Could not normalize input. Error: %s", u_errorName(status));
86 }
87 }
88}
89UChar* NormalizerPerformanceTest::normalizeInput(int32_t& len, const UChar* src ,int32_t srcLen,UNormalizationMode mode, int32_t options){
90 int32_t reqLen = 0;
91 UErrorCode status = U_ZERO_ERROR;
92 UChar* dest = NULL;
93 for(;;){
94 /* pure pre-flight */
95 reqLen=unorm_normalize(src,srcLen,mode, options,NULL,0,&status);
96 if(status==U_BUFFER_OVERFLOW_ERROR){
97 status=U_ZERO_ERROR;
98 dest = new UChar[reqLen+1];
99 reqLen= unorm_normalize(src,srcLen,mode, options,dest,reqLen+1,&status);
100 len=reqLen;
101 break;
102 }else if(U_FAILURE(status)){
103 printf("Could not normalize input. Error: %s", u_errorName(status));
104 return NULL;
105 }
106 }
107 return dest;
108}
109
110static UOption cmdLineOptions[]={
111 UOPTION_DEF("options", 'o', UOPT_OPTIONAL_ARG)
112};
113
114NormalizerPerformanceTest::NormalizerPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status)
115: UPerfTest(argc,argv,status), options(0) {
116 NFDBuffer = NULL;
117 NFCBuffer = NULL;
118 NFDBufferLen = 0;
119 NFCBufferLen = 0;
120 NFDFileLines = NULL;
121 NFCFileLines = NULL;
122
123 if(status== U_ILLEGAL_ARGUMENT_ERROR){
124 fprintf(stderr,gUsageString, "normperf");
125 return;
126 }
127
128 if(U_FAILURE(status)){
129 fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status));
130 return;
131 }
132
133 _remainingArgc = u_parseArgs(_remainingArgc, (char **)argv, (int32_t)(LENGTHOF(cmdLineOptions)), cmdLineOptions);
134 if(cmdLineOptions[0].doesOccur && cmdLineOptions[0].value!=NULL) {
135 options=(int32_t)strtol(cmdLineOptions[0].value, NULL, 16);
136 }
137
138 if(line_mode){
139 ULine* filelines = getLines(status);
140 if(U_FAILURE(status)){
141 fprintf(stderr, "FAILED to read lines from file and create UPerfTest object. Error: %s\n", u_errorName(status));
142 return;
143 }
144 NFDFileLines = new ULine[numLines];
145 NFCFileLines = new ULine[numLines];
146
147 for(int32_t i=0;i<numLines;i++){
148 normalizeInput(&NFDFileLines[i],filelines[i].name,filelines[i].len,UNORM_NFD, options);
149 normalizeInput(&NFCFileLines[i],filelines[i].name,filelines[i].len,UNORM_NFC, options);
150
151 }
152 }else if(bulk_mode){
153 int32_t srcLen = 0;
154 const UChar* src = getBuffer(srcLen,status);
155 NFDBufferLen = 0;
156 NFCBufferLen = 0;
157
158 if(U_FAILURE(status)){
159 fprintf(stderr, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status));
160 return;
161 }
162
163 NFDBuffer = normalizeInput(NFDBufferLen,src,srcLen,UNORM_NFD, options);
164 NFCBuffer = normalizeInput(NFCBufferLen,src,srcLen,UNORM_NFC, options);
165 }
166
167}
168
169NormalizerPerformanceTest::~NormalizerPerformanceTest(){
170 delete[] NFDFileLines;
171 delete[] NFCFileLines;
172 delete[] NFDBuffer;
173 delete[] NFCBuffer;
174}
175
176// Test NFC Performance
177UPerfFunction* NormalizerPerformanceTest::TestICU_NFC_NFD_Text(){
178 if(line_mode){
179 NormPerfFunction* func= new NormPerfFunction(ICUNormNFC, options,NFDFileLines,numLines, uselen);
180 return func;
181 }else{
182 NormPerfFunction* func= new NormPerfFunction(ICUNormNFC, options,NFDBuffer, NFDBufferLen, uselen);
183 return func;
184 }
185}
186UPerfFunction* NormalizerPerformanceTest::TestICU_NFC_NFC_Text(){
187 if(line_mode){
188 NormPerfFunction* func = new NormPerfFunction(ICUNormNFC, options,NFCFileLines,numLines, uselen);
189 return func;
190 }else{
191 NormPerfFunction* func= new NormPerfFunction(ICUNormNFC, options,NFCBuffer, NFCBufferLen, uselen);
192 return func;
193 }
194}
195UPerfFunction* NormalizerPerformanceTest::TestICU_NFC_Orig_Text(){
196 if(line_mode){
197 NormPerfFunction* func = new NormPerfFunction(ICUNormNFC, options,lines,numLines, uselen);
198 return func;
199 }else{
200 NormPerfFunction* func = new NormPerfFunction(ICUNormNFC, options,buffer, bufferLen, uselen);
201 return func;
202 }
203}
204
205// Test NFD Performance
206UPerfFunction* NormalizerPerformanceTest::TestICU_NFD_NFD_Text(){
207 if(line_mode){
208 NormPerfFunction* func = new NormPerfFunction(ICUNormNFD, options,NFDFileLines,numLines, uselen);
209 return func;
210 }else{
211 NormPerfFunction* func = new NormPerfFunction(ICUNormNFD, options,NFDBuffer,NFDBufferLen, uselen);
212 return func;
213 }
214}
215UPerfFunction* NormalizerPerformanceTest::TestICU_NFD_NFC_Text(){
216 if(line_mode){
217 NormPerfFunction* func = new NormPerfFunction(ICUNormNFD, options,NFCFileLines,numLines, uselen);
218 return func;
219 }else{
220 NormPerfFunction* func = new NormPerfFunction(ICUNormNFD, options,NFCBuffer,NFCBufferLen, uselen);
221 return func;
222 }
223}
224UPerfFunction* NormalizerPerformanceTest::TestICU_NFD_Orig_Text(){
225 if(line_mode){
226 NormPerfFunction* func = new NormPerfFunction(ICUNormNFD, options,lines,numLines, uselen);
227 return func;
228 }else{
229 NormPerfFunction* func = new NormPerfFunction(ICUNormNFD, options,buffer,bufferLen, uselen);
230 return func;
231 }
232}
233
234// Test FCD Performance
235UPerfFunction* NormalizerPerformanceTest::TestICU_FCD_NFD_Text(){
236 if(line_mode){
237 NormPerfFunction* func = new NormPerfFunction(ICUNormFCD, options,NFDFileLines,numLines, uselen);
238 return func;
239 }else{
240 NormPerfFunction* func = new NormPerfFunction(ICUNormFCD, options,NFDBuffer,NFDBufferLen, uselen);
241 return func;
242 }
243
244}
245UPerfFunction* NormalizerPerformanceTest::TestICU_FCD_NFC_Text(){
246 if(line_mode){
247 NormPerfFunction* func = new NormPerfFunction(ICUNormFCD, options,NFCFileLines,numLines, uselen);
248 return func;
249 }else{
250 NormPerfFunction* func = new NormPerfFunction(ICUNormFCD, options,NFCBuffer,NFCBufferLen, uselen);
251 return func;
252 }
253}
254UPerfFunction* NormalizerPerformanceTest::TestICU_FCD_Orig_Text(){
255 if(line_mode){
256 NormPerfFunction* func = new NormPerfFunction(ICUNormFCD, options,lines,numLines, uselen);
257 return func;
258 }else{
259 NormPerfFunction* func = new NormPerfFunction(ICUNormFCD, options,buffer,bufferLen, uselen);
260 return func;
261 }
262}
263
264// Test Win NFC Performance
265UPerfFunction* NormalizerPerformanceTest::TestWin_NFC_NFD_Text(){
266 if(line_mode){
267 NormPerfFunction* func = new NormPerfFunction(WinNormNFC, options,NFDFileLines,numLines, uselen);
268 return func;
269 }else{
270 NormPerfFunction* func = new NormPerfFunction(WinNormNFC, options,NFDBuffer,NFDBufferLen, uselen);
271 return func;
272 }
273}
274UPerfFunction* NormalizerPerformanceTest::TestWin_NFC_NFC_Text(){
275 if(line_mode){
276 NormPerfFunction* func = new NormPerfFunction(WinNormNFC, options,NFCFileLines,numLines, uselen);
277 return func;
278 }else{
279 NormPerfFunction* func = new NormPerfFunction(WinNormNFC, options,NFCBuffer,NFCBufferLen, uselen);
280 return func;
281 }
282}
283UPerfFunction* NormalizerPerformanceTest::TestWin_NFC_Orig_Text(){
284 if(line_mode){
285 NormPerfFunction* func = new NormPerfFunction(WinNormNFC, options,lines,numLines, uselen);
286 return func;
287 }else{
288 NormPerfFunction* func = new NormPerfFunction(WinNormNFC, options,buffer,bufferLen, uselen);
289 return func;
290 }
291}
292
293// Test Win NFD Performance
294UPerfFunction* NormalizerPerformanceTest::TestWin_NFD_NFD_Text(){
295 if(line_mode){
296 NormPerfFunction* func = new NormPerfFunction(WinNormNFD, options,NFDFileLines,numLines, uselen);
297 return func;
298 }else{
299 NormPerfFunction* func = new NormPerfFunction(WinNormNFD, options,NFDBuffer,NFDBufferLen, uselen);
300 return func;
301 }
302}
303UPerfFunction* NormalizerPerformanceTest::TestWin_NFD_NFC_Text(){
304 if(line_mode){
305 NormPerfFunction* func = new NormPerfFunction(WinNormNFD, options,NFCFileLines,numLines, uselen);
306 return func;
307 }else{
308 NormPerfFunction* func = new NormPerfFunction(WinNormNFD, options,NFCBuffer,NFCBufferLen, uselen);
309 return func;
310 }
311}
312UPerfFunction* NormalizerPerformanceTest::TestWin_NFD_Orig_Text(){
313 if(line_mode){
314 NormPerfFunction* func = new NormPerfFunction(WinNormNFD, options,lines,numLines, uselen);
315 return func;
316 }else{
317 NormPerfFunction* func = new NormPerfFunction(WinNormNFD, options,buffer,bufferLen, uselen);
318 return func;
319 }
320}
321
322// Test Quick Check Performance
323UPerfFunction* NormalizerPerformanceTest::TestQC_NFC_NFD_Text(){
324 if(line_mode){
325 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFDFileLines, numLines, UNORM_NFC, options,uselen);
326 return func;
327 }else{
328 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFDBuffer, NFDBufferLen, UNORM_NFC, options,uselen);
329 return func;
330 }
331}
332UPerfFunction* NormalizerPerformanceTest::TestQC_NFC_NFC_Text(){
333 if(line_mode){
334 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFCFileLines, numLines, UNORM_NFC, options,uselen);
335 return func;
336 }else{
337 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFCBuffer, NFCBufferLen, UNORM_NFC, options,uselen);
338 return func;
339 }
340}
341UPerfFunction* NormalizerPerformanceTest::TestQC_NFC_Orig_Text(){
342 if(line_mode){
343 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,lines, numLines, UNORM_NFC, options,uselen);
344 return func;
345 }else{
346 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,buffer, bufferLen, UNORM_NFC, options,uselen);
347 return func;
348 }
349}
350
351UPerfFunction* NormalizerPerformanceTest::TestQC_NFD_NFD_Text(){
352 if(line_mode){
353 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFDFileLines, numLines, UNORM_NFD, options,uselen);
354 return func;
355 }else{
356 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFDBuffer, NFDBufferLen, UNORM_NFD, options,uselen);
357 return func;
358 }
359}
360UPerfFunction* NormalizerPerformanceTest::TestQC_NFD_NFC_Text(){
361 if(line_mode){
362 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFCFileLines, numLines, UNORM_NFD, options,uselen);
363 return func;
364 }else{
365 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFCBuffer, NFCBufferLen, UNORM_NFD, options,uselen);
366 return func;
367 }
368}
369UPerfFunction* NormalizerPerformanceTest::TestQC_NFD_Orig_Text(){
370 if(line_mode){
371 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,lines, numLines, UNORM_NFD, options,uselen);
372 return func;
373 }else{
374 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,buffer, bufferLen, UNORM_NFD, options,uselen);
375 return func;
376 }
377}
378
379UPerfFunction* NormalizerPerformanceTest::TestQC_FCD_NFD_Text(){
380 if(line_mode){
381 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFDFileLines, numLines, UNORM_FCD, options,uselen);
382 return func;
383 }else{
384 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFDBuffer, NFDBufferLen, UNORM_FCD, options,uselen);
385 return func;
386 }
387}
388UPerfFunction* NormalizerPerformanceTest::TestQC_FCD_NFC_Text(){
389 if(line_mode){
390 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFCFileLines, numLines, UNORM_FCD, options,uselen);
391 return func;
392 }else{
393 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,NFCBuffer, NFCBufferLen, UNORM_FCD, options,uselen);
394 return func;
395 }
396}
397UPerfFunction* NormalizerPerformanceTest::TestQC_FCD_Orig_Text(){
398 if(line_mode){
399 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,lines, numLines, UNORM_FCD, options,uselen);
400 return func;
401 }else{
402 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUQuickCheck,buffer, bufferLen, UNORM_FCD, options,uselen);
403 return func;
404 }
405}
406
407// Test isNormalized Performance
408UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_NFC_NFD_Text(){
409 if(line_mode){
410 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFDFileLines, numLines, UNORM_NFC, options,uselen);
411 return func;
412 }else{
413 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFDBuffer, NFDBufferLen, UNORM_NFC, options,uselen);
414 return func;
415 }
416}
417UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_NFC_NFC_Text(){
418 if(line_mode){
419 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFCFileLines, numLines, UNORM_NFC, options,uselen);
420 return func;
421 }else{
422 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFCBuffer, NFCBufferLen, UNORM_NFC, options,uselen);
423 return func;
424 }
425}
426UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_NFC_Orig_Text(){
427 if(line_mode){
428 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,lines, numLines, UNORM_NFC, options,uselen);
429 return func;
430 }else{
431 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,buffer, bufferLen, UNORM_NFC, options,uselen);
432 return func;
433 }
434}
435
436UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_NFD_NFD_Text(){
437 if(line_mode){
438 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFDFileLines, numLines, UNORM_NFD, options,uselen);
439 return func;
440 }else{
441 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFDBuffer, NFDBufferLen, UNORM_NFD, options,uselen);
442 return func;
443 }
444}
445UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_NFD_NFC_Text(){
446 if(line_mode){
447 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFCFileLines, numLines, UNORM_NFD, options,uselen);
448 return func;
449 }else{
450 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFCBuffer, NFCBufferLen, UNORM_NFD, options,uselen);
451 return func;
452 }
453}
454UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_NFD_Orig_Text(){
455 if(line_mode){
456 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,lines, numLines, UNORM_NFD, options,uselen);
457 return func;
458 }else{
459 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,buffer, bufferLen, UNORM_NFD, options,uselen);
460 return func;
461 }
462}
463
464UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_FCD_NFD_Text(){
465 if(line_mode){
466 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFDFileLines, numLines, UNORM_FCD, options,uselen);
467 return func;
468 }else{
469 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFDBuffer, NFDBufferLen, UNORM_FCD, options,uselen);
470 return func;
471 }
472}
473UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_FCD_NFC_Text(){
474 if(line_mode){
475 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFCFileLines, numLines, UNORM_FCD, options,uselen);
476 return func;
477 }else{
478 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,NFCBuffer, NFCBufferLen, UNORM_FCD, options,uselen);
479 return func;
480 }
481}
482UPerfFunction* NormalizerPerformanceTest::TestIsNormalized_FCD_Orig_Text(){
483 if(line_mode){
484 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,lines, numLines, UNORM_FCD, options,uselen);
485 return func;
486 }else{
487 QuickCheckPerfFunction* func = new QuickCheckPerfFunction(ICUIsNormalized,buffer, bufferLen, UNORM_FCD, options,uselen);
488 return func;
489 }
490}
491
492int main(int argc, const char* argv[]){
493 UErrorCode status = U_ZERO_ERROR;
494 NormalizerPerformanceTest test(argc, argv, status);
495 if(U_FAILURE(status)){
496 return status;
497 }
498 if(test.run()==FALSE){
499 fprintf(stderr,"FAILED: Tests could not be run please check the arguments.\n");
500 return -1;
501 }
502 return 0;
503}