2 ***********************************************************************
3 * © 2016 and later: Unicode, Inc. and others.
4 * License & terms of use: http://www.unicode.org/copyright.html#License
5 ***********************************************************************
6 ***********************************************************************
7 * Copyright (c) 2002-2016, International Business Machines
8 * Corporation and others. All Rights Reserved.
9 ***********************************************************************
10 ***********************************************************************
13 * This Program tests the performance of ICU's Normalization engine against Windows
14 * to run it use the command like
16 * c:\normperf.exe -s C:\work\ICUCupertinoRep\icu4c\collation-perf-data -i 10 -p 15 -f TestNames_Asian.txt -u -e UTF-8 -l
20 #include "cmemory.h" // for UPRV_LENGTHOF
23 UPerfFunction
* NormalizerPerformanceTest::runIndexedTest(int32_t index
, UBool exec
,const char* &name
, char* par
) {
25 TESTCASE(0,TestICU_NFC_NFD_Text
);
26 TESTCASE(1,TestICU_NFC_NFC_Text
);
27 TESTCASE(2,TestICU_NFC_Orig_Text
);
29 TESTCASE(3,TestICU_NFD_NFD_Text
);
30 TESTCASE(4,TestICU_NFD_NFC_Text
);
31 TESTCASE(5,TestICU_NFD_Orig_Text
);
33 TESTCASE(6,TestICU_FCD_NFD_Text
);
34 TESTCASE(7,TestICU_FCD_NFC_Text
);
35 TESTCASE(8,TestICU_FCD_Orig_Text
);
37 TESTCASE(9,TestWin_NFC_NFD_Text
);
38 TESTCASE(10,TestWin_NFC_NFC_Text
);
39 TESTCASE(11,TestWin_NFC_Orig_Text
);
41 TESTCASE(12,TestWin_NFD_NFD_Text
);
42 TESTCASE(13,TestWin_NFD_NFC_Text
);
43 TESTCASE(14,TestWin_NFD_Orig_Text
);
45 TESTCASE(15,TestQC_NFC_NFD_Text
);
46 TESTCASE(16,TestQC_NFC_NFC_Text
);
47 TESTCASE(17,TestQC_NFC_Orig_Text
);
49 TESTCASE(18,TestQC_NFD_NFD_Text
);
50 TESTCASE(19,TestQC_NFD_NFC_Text
);
51 TESTCASE(20,TestQC_NFD_Orig_Text
);
53 TESTCASE(21,TestQC_FCD_NFD_Text
);
54 TESTCASE(22,TestQC_FCD_NFC_Text
);
55 TESTCASE(23,TestQC_FCD_Orig_Text
);
57 TESTCASE(24,TestIsNormalized_NFC_NFD_Text
);
58 TESTCASE(25,TestIsNormalized_NFC_NFC_Text
);
59 TESTCASE(26,TestIsNormalized_NFC_Orig_Text
);
61 TESTCASE(27,TestIsNormalized_NFD_NFD_Text
);
62 TESTCASE(28,TestIsNormalized_NFD_NFC_Text
);
63 TESTCASE(29,TestIsNormalized_NFD_Orig_Text
);
65 TESTCASE(30,TestIsNormalized_FCD_NFD_Text
);
66 TESTCASE(31,TestIsNormalized_FCD_NFC_Text
);
67 TESTCASE(32,TestIsNormalized_FCD_Orig_Text
);
77 void NormalizerPerformanceTest::normalizeInput(ULine
* dest
,const UChar
* src
,int32_t srcLen
,UNormalizationMode mode
, int32_t options
){
79 UErrorCode status
= U_ZERO_ERROR
;
82 reqLen
=unorm_normalize(src
,srcLen
,mode
, options
,NULL
,0,&status
);
83 if(status
==U_BUFFER_OVERFLOW_ERROR
){
85 dest
->name
= new UChar
[reqLen
+1];
86 reqLen
= unorm_normalize(src
,srcLen
,mode
, options
,dest
->name
,reqLen
+1,&status
);
89 }else if(U_FAILURE(status
)){
90 printf("Could not normalize input. Error: %s", u_errorName(status
));
94 UChar
* NormalizerPerformanceTest::normalizeInput(int32_t& len
, const UChar
* src
,int32_t srcLen
,UNormalizationMode mode
, int32_t options
){
96 UErrorCode status
= U_ZERO_ERROR
;
100 reqLen
=unorm_normalize(src
,srcLen
,mode
, options
,NULL
,0,&status
);
101 if(status
==U_BUFFER_OVERFLOW_ERROR
){
103 dest
= new UChar
[reqLen
+1];
104 reqLen
= unorm_normalize(src
,srcLen
,mode
, options
,dest
,reqLen
+1,&status
);
107 }else if(U_FAILURE(status
)){
108 printf("Could not normalize input. Error: %s", u_errorName(status
));
115 static UOption cmdLineOptions
[]={
116 UOPTION_DEF("options", 'o', UOPT_OPTIONAL_ARG
)
119 NormalizerPerformanceTest::NormalizerPerformanceTest(int32_t argc
, const char* argv
[], UErrorCode
& status
)
120 : UPerfTest(argc
,argv
,status
), options(0) {
128 if(status
== U_ILLEGAL_ARGUMENT_ERROR
){
129 fprintf(stderr
,gUsageString
, "normperf");
133 if(U_FAILURE(status
)){
134 fprintf(stderr
, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status
));
138 _remainingArgc
= u_parseArgs(_remainingArgc
, (char **)argv
, UPRV_LENGTHOF(cmdLineOptions
), cmdLineOptions
);
139 if(cmdLineOptions
[0].doesOccur
&& cmdLineOptions
[0].value
!=NULL
) {
140 options
=(int32_t)strtol(cmdLineOptions
[0].value
, NULL
, 16);
144 ULine
* filelines
= getLines(status
);
145 if(U_FAILURE(status
)){
146 fprintf(stderr
, "FAILED to read lines from file and create UPerfTest object. Error: %s\n", u_errorName(status
));
149 NFDFileLines
= new ULine
[numLines
];
150 NFCFileLines
= new ULine
[numLines
];
152 for(int32_t i
=0;i
<numLines
;i
++){
153 normalizeInput(&NFDFileLines
[i
],filelines
[i
].name
,filelines
[i
].len
,UNORM_NFD
, options
);
154 normalizeInput(&NFCFileLines
[i
],filelines
[i
].name
,filelines
[i
].len
,UNORM_NFC
, options
);
159 const UChar
* src
= getBuffer(srcLen
,status
);
163 if(U_FAILURE(status
)){
164 fprintf(stderr
, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status
));
168 NFDBuffer
= normalizeInput(NFDBufferLen
,src
,srcLen
,UNORM_NFD
, options
);
169 NFCBuffer
= normalizeInput(NFCBufferLen
,src
,srcLen
,UNORM_NFC
, options
);
174 NormalizerPerformanceTest::~NormalizerPerformanceTest(){
175 delete[] NFDFileLines
;
176 delete[] NFCFileLines
;
181 // Test NFC Performance
182 UPerfFunction
* NormalizerPerformanceTest::TestICU_NFC_NFD_Text(){
184 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFC
, options
,NFDFileLines
,numLines
, uselen
);
187 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFC
, options
,NFDBuffer
, NFDBufferLen
, uselen
);
191 UPerfFunction
* NormalizerPerformanceTest::TestICU_NFC_NFC_Text(){
193 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFC
, options
,NFCFileLines
,numLines
, uselen
);
196 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFC
, options
,NFCBuffer
, NFCBufferLen
, uselen
);
200 UPerfFunction
* NormalizerPerformanceTest::TestICU_NFC_Orig_Text(){
202 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFC
, options
,lines
,numLines
, uselen
);
205 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFC
, options
,buffer
, bufferLen
, uselen
);
210 // Test NFD Performance
211 UPerfFunction
* NormalizerPerformanceTest::TestICU_NFD_NFD_Text(){
213 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFD
, options
,NFDFileLines
,numLines
, uselen
);
216 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFD
, options
,NFDBuffer
,NFDBufferLen
, uselen
);
220 UPerfFunction
* NormalizerPerformanceTest::TestICU_NFD_NFC_Text(){
222 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFD
, options
,NFCFileLines
,numLines
, uselen
);
225 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFD
, options
,NFCBuffer
,NFCBufferLen
, uselen
);
229 UPerfFunction
* NormalizerPerformanceTest::TestICU_NFD_Orig_Text(){
231 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFD
, options
,lines
,numLines
, uselen
);
234 NormPerfFunction
* func
= new NormPerfFunction(ICUNormNFD
, options
,buffer
,bufferLen
, uselen
);
239 // Test FCD Performance
240 UPerfFunction
* NormalizerPerformanceTest::TestICU_FCD_NFD_Text(){
242 NormPerfFunction
* func
= new NormPerfFunction(ICUNormFCD
, options
,NFDFileLines
,numLines
, uselen
);
245 NormPerfFunction
* func
= new NormPerfFunction(ICUNormFCD
, options
,NFDBuffer
,NFDBufferLen
, uselen
);
250 UPerfFunction
* NormalizerPerformanceTest::TestICU_FCD_NFC_Text(){
252 NormPerfFunction
* func
= new NormPerfFunction(ICUNormFCD
, options
,NFCFileLines
,numLines
, uselen
);
255 NormPerfFunction
* func
= new NormPerfFunction(ICUNormFCD
, options
,NFCBuffer
,NFCBufferLen
, uselen
);
259 UPerfFunction
* NormalizerPerformanceTest::TestICU_FCD_Orig_Text(){
261 NormPerfFunction
* func
= new NormPerfFunction(ICUNormFCD
, options
,lines
,numLines
, uselen
);
264 NormPerfFunction
* func
= new NormPerfFunction(ICUNormFCD
, options
,buffer
,bufferLen
, uselen
);
269 // Test Win NFC Performance
270 UPerfFunction
* NormalizerPerformanceTest::TestWin_NFC_NFD_Text(){
272 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFC
, options
,NFDFileLines
,numLines
, uselen
);
275 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFC
, options
,NFDBuffer
,NFDBufferLen
, uselen
);
279 UPerfFunction
* NormalizerPerformanceTest::TestWin_NFC_NFC_Text(){
281 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFC
, options
,NFCFileLines
,numLines
, uselen
);
284 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFC
, options
,NFCBuffer
,NFCBufferLen
, uselen
);
288 UPerfFunction
* NormalizerPerformanceTest::TestWin_NFC_Orig_Text(){
290 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFC
, options
,lines
,numLines
, uselen
);
293 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFC
, options
,buffer
,bufferLen
, uselen
);
298 // Test Win NFD Performance
299 UPerfFunction
* NormalizerPerformanceTest::TestWin_NFD_NFD_Text(){
301 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFD
, options
,NFDFileLines
,numLines
, uselen
);
304 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFD
, options
,NFDBuffer
,NFDBufferLen
, uselen
);
308 UPerfFunction
* NormalizerPerformanceTest::TestWin_NFD_NFC_Text(){
310 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFD
, options
,NFCFileLines
,numLines
, uselen
);
313 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFD
, options
,NFCBuffer
,NFCBufferLen
, uselen
);
317 UPerfFunction
* NormalizerPerformanceTest::TestWin_NFD_Orig_Text(){
319 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFD
, options
,lines
,numLines
, uselen
);
322 NormPerfFunction
* func
= new NormPerfFunction(WinNormNFD
, options
,buffer
,bufferLen
, uselen
);
327 // Test Quick Check Performance
328 UPerfFunction
* NormalizerPerformanceTest::TestQC_NFC_NFD_Text(){
330 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFDFileLines
, numLines
, UNORM_NFC
, options
,uselen
);
333 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFDBuffer
, NFDBufferLen
, UNORM_NFC
, options
,uselen
);
337 UPerfFunction
* NormalizerPerformanceTest::TestQC_NFC_NFC_Text(){
339 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFCFileLines
, numLines
, UNORM_NFC
, options
,uselen
);
342 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFCBuffer
, NFCBufferLen
, UNORM_NFC
, options
,uselen
);
346 UPerfFunction
* NormalizerPerformanceTest::TestQC_NFC_Orig_Text(){
348 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,lines
, numLines
, UNORM_NFC
, options
,uselen
);
351 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,buffer
, bufferLen
, UNORM_NFC
, options
,uselen
);
356 UPerfFunction
* NormalizerPerformanceTest::TestQC_NFD_NFD_Text(){
358 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFDFileLines
, numLines
, UNORM_NFD
, options
,uselen
);
361 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFDBuffer
, NFDBufferLen
, UNORM_NFD
, options
,uselen
);
365 UPerfFunction
* NormalizerPerformanceTest::TestQC_NFD_NFC_Text(){
367 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFCFileLines
, numLines
, UNORM_NFD
, options
,uselen
);
370 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFCBuffer
, NFCBufferLen
, UNORM_NFD
, options
,uselen
);
374 UPerfFunction
* NormalizerPerformanceTest::TestQC_NFD_Orig_Text(){
376 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,lines
, numLines
, UNORM_NFD
, options
,uselen
);
379 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,buffer
, bufferLen
, UNORM_NFD
, options
,uselen
);
384 UPerfFunction
* NormalizerPerformanceTest::TestQC_FCD_NFD_Text(){
386 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFDFileLines
, numLines
, UNORM_FCD
, options
,uselen
);
389 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFDBuffer
, NFDBufferLen
, UNORM_FCD
, options
,uselen
);
393 UPerfFunction
* NormalizerPerformanceTest::TestQC_FCD_NFC_Text(){
395 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFCFileLines
, numLines
, UNORM_FCD
, options
,uselen
);
398 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,NFCBuffer
, NFCBufferLen
, UNORM_FCD
, options
,uselen
);
402 UPerfFunction
* NormalizerPerformanceTest::TestQC_FCD_Orig_Text(){
404 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,lines
, numLines
, UNORM_FCD
, options
,uselen
);
407 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUQuickCheck
,buffer
, bufferLen
, UNORM_FCD
, options
,uselen
);
412 // Test isNormalized Performance
413 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_NFC_NFD_Text(){
415 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFDFileLines
, numLines
, UNORM_NFC
, options
,uselen
);
418 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFDBuffer
, NFDBufferLen
, UNORM_NFC
, options
,uselen
);
422 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_NFC_NFC_Text(){
424 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFCFileLines
, numLines
, UNORM_NFC
, options
,uselen
);
427 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFCBuffer
, NFCBufferLen
, UNORM_NFC
, options
,uselen
);
431 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_NFC_Orig_Text(){
433 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,lines
, numLines
, UNORM_NFC
, options
,uselen
);
436 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,buffer
, bufferLen
, UNORM_NFC
, options
,uselen
);
441 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_NFD_NFD_Text(){
443 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFDFileLines
, numLines
, UNORM_NFD
, options
,uselen
);
446 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFDBuffer
, NFDBufferLen
, UNORM_NFD
, options
,uselen
);
450 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_NFD_NFC_Text(){
452 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFCFileLines
, numLines
, UNORM_NFD
, options
,uselen
);
455 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFCBuffer
, NFCBufferLen
, UNORM_NFD
, options
,uselen
);
459 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_NFD_Orig_Text(){
461 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,lines
, numLines
, UNORM_NFD
, options
,uselen
);
464 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,buffer
, bufferLen
, UNORM_NFD
, options
,uselen
);
469 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_FCD_NFD_Text(){
471 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFDFileLines
, numLines
, UNORM_FCD
, options
,uselen
);
474 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFDBuffer
, NFDBufferLen
, UNORM_FCD
, options
,uselen
);
478 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_FCD_NFC_Text(){
480 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFCFileLines
, numLines
, UNORM_FCD
, options
,uselen
);
483 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,NFCBuffer
, NFCBufferLen
, UNORM_FCD
, options
,uselen
);
487 UPerfFunction
* NormalizerPerformanceTest::TestIsNormalized_FCD_Orig_Text(){
489 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,lines
, numLines
, UNORM_FCD
, options
,uselen
);
492 QuickCheckPerfFunction
* func
= new QuickCheckPerfFunction(ICUIsNormalized
,buffer
, bufferLen
, UNORM_FCD
, options
,uselen
);
497 int main(int argc
, const char* argv
[]){
498 UErrorCode status
= U_ZERO_ERROR
;
499 NormalizerPerformanceTest
test(argc
, argv
, status
);
500 if(U_FAILURE(status
)){
503 if(test
.run()==FALSE
){
504 fprintf(stderr
,"FAILED: Tests could not be run please check the arguments.\n");