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) 2013-2014, International Business Machines
8 * Corporation and others. All Rights Reserved.
9 ***********************************************************************
13 #include "unicode/localpointer.h"
14 #include "unicode/uperf.h"
15 #include "unicode/ucol.h"
16 #include "unicode/coll.h"
17 #include "unicode/uiter.h"
18 #include "unicode/ustring.h"
19 #include "unicode/sortkey.h"
24 #define COMPACT_ARRAY(CompactArrays, UNIT) \
25 struct CompactArrays{\
26 CompactArrays(const CompactArrays & );\
27 CompactArrays & operator=(const CompactArrays & );\
28 int32_t count;/*total number of the strings*/ \
29 int32_t * index;/*relative offset in data*/ \
30 UNIT * data; /*the real space to hold strings*/ \
32 ~CompactArrays(){free(index);free(data);} \
33 CompactArrays() : count(0), index(NULL), data(NULL) { \
34 index = (int32_t *) realloc(index, sizeof(int32_t)); \
37 void append_one(int32_t theLen){ /*include terminal NULL*/ \
39 index = (int32_t *) realloc(index, sizeof(int32_t) * (count + 1)); \
40 index[count] = index[count - 1] + theLen; \
41 data = (UNIT *) realloc(data, sizeof(UNIT) * index[count]); \
43 UNIT * last(){return data + index[count - 1];} \
44 const UNIT * dataOf(int32_t i) const {return data + index[i];} \
45 int32_t lengthOf(int i) const {return index[i+1] - index[i] - 1; } /*exclude terminating NULL*/ \
48 COMPACT_ARRAY(CA_uchar
, UChar
)
49 COMPACT_ARRAY(CA_char
, char)
51 #define MAX_TEST_STRINGS_FOR_PERMUTING 1000
56 // Test case taking a single test data array, calling ucol_strcoll by permuting the test data
58 class Strcoll
: public UPerfFunction
61 Strcoll(const UCollator
* coll
, const CA_uchar
* source
, UBool useLen
);
63 virtual void call(UErrorCode
* status
);
64 virtual long getOperationsPerIteration();
67 const UCollator
*coll
;
68 const CA_uchar
*source
;
70 int32_t maxTestStrings
;
73 Strcoll::Strcoll(const UCollator
* coll
, const CA_uchar
* source
, UBool useLen
)
78 maxTestStrings
= source
->count
> MAX_TEST_STRINGS_FOR_PERMUTING
? MAX_TEST_STRINGS_FOR_PERMUTING
: source
->count
;
85 void Strcoll::call(UErrorCode
* status
)
87 if (U_FAILURE(*status
)) return;
89 // call strcoll for permutation
90 int32_t divisor
= source
->count
/ maxTestStrings
;
91 int32_t srcLen
, tgtLen
;
93 for (int32_t i
= 0, numTestStringsI
= 0; i
< source
->count
&& numTestStringsI
< maxTestStrings
; i
++) {
94 if (i
% divisor
) continue;
96 srcLen
= useLen
? source
->lengthOf(i
) : -1;
97 for (int32_t j
= 0, numTestStringsJ
= 0; j
< source
->count
&& numTestStringsJ
< maxTestStrings
; j
++) {
98 if (j
% divisor
) continue;
100 tgtLen
= useLen
? source
->lengthOf(j
) : -1;
101 cmp
+= ucol_strcoll(coll
, source
->dataOf(i
), srcLen
, source
->dataOf(j
), tgtLen
);
104 // At the end, cmp must be 0
106 *status
= U_INTERNAL_PROGRAM_ERROR
;
110 long Strcoll::getOperationsPerIteration()
112 return maxTestStrings
* maxTestStrings
;
116 // Test case taking two test data arrays, calling ucol_strcoll for strings at a same index
118 class Strcoll_2
: public UPerfFunction
121 Strcoll_2(const UCollator
* coll
, const CA_uchar
* source
, const CA_uchar
* target
, UBool useLen
);
123 virtual void call(UErrorCode
* status
);
124 virtual long getOperationsPerIteration();
127 const UCollator
*coll
;
128 const CA_uchar
*source
;
129 const CA_uchar
*target
;
133 Strcoll_2::Strcoll_2(const UCollator
* coll
, const CA_uchar
* source
, const CA_uchar
* target
, UBool useLen
)
141 Strcoll_2::~Strcoll_2()
145 void Strcoll_2::call(UErrorCode
* status
)
147 if (U_FAILURE(*status
)) return;
149 // call strcoll for two strings at the same index
150 if (source
->count
< target
->count
) {
151 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
153 for (int32_t i
= 0; i
< source
->count
; i
++) {
154 int32_t srcLen
= useLen
? source
->lengthOf(i
) : -1;
155 int32_t tgtLen
= useLen
? target
->lengthOf(i
) : -1;
156 ucol_strcoll(coll
, source
->dataOf(i
), srcLen
, target
->dataOf(i
), tgtLen
);
161 long Strcoll_2::getOperationsPerIteration()
163 return source
->count
;
168 // Test case taking a single test data array, calling ucol_strcollUTF8 by permuting the test data
170 class StrcollUTF8
: public UPerfFunction
173 StrcollUTF8(const UCollator
* coll
, const CA_char
* source
, UBool useLen
);
175 virtual void call(UErrorCode
* status
);
176 virtual long getOperationsPerIteration();
179 const UCollator
*coll
;
180 const CA_char
*source
;
182 int32_t maxTestStrings
;
185 StrcollUTF8::StrcollUTF8(const UCollator
* coll
, const CA_char
* source
, UBool useLen
)
190 maxTestStrings
= source
->count
> MAX_TEST_STRINGS_FOR_PERMUTING
? MAX_TEST_STRINGS_FOR_PERMUTING
: source
->count
;
193 StrcollUTF8::~StrcollUTF8()
197 void StrcollUTF8::call(UErrorCode
* status
)
199 if (U_FAILURE(*status
)) return;
201 // call strcollUTF8 for permutation
202 int32_t divisor
= source
->count
/ maxTestStrings
;
203 int32_t srcLen
, tgtLen
;
205 for (int32_t i
= 0, numTestStringsI
= 0; U_SUCCESS(*status
) && i
< source
->count
&& numTestStringsI
< maxTestStrings
; i
++) {
206 if (i
% divisor
) continue;
208 srcLen
= useLen
? source
->lengthOf(i
) : -1;
209 for (int32_t j
= 0, numTestStringsJ
= 0; U_SUCCESS(*status
) && j
< source
->count
&& numTestStringsJ
< maxTestStrings
; j
++) {
210 if (j
% divisor
) continue;
212 tgtLen
= useLen
? source
->lengthOf(j
) : -1;
213 cmp
+= ucol_strcollUTF8(coll
, source
->dataOf(i
), srcLen
, source
->dataOf(j
), tgtLen
, status
);
216 // At the end, cmp must be 0
218 *status
= U_INTERNAL_PROGRAM_ERROR
;
222 long StrcollUTF8::getOperationsPerIteration()
224 return maxTestStrings
* maxTestStrings
;
228 // Test case taking two test data arrays, calling ucol_strcoll for strings at a same index
230 class StrcollUTF8_2
: public UPerfFunction
233 StrcollUTF8_2(const UCollator
* coll
, const CA_char
* source
, const CA_char
* target
, UBool useLen
);
235 virtual void call(UErrorCode
* status
);
236 virtual long getOperationsPerIteration();
239 const UCollator
*coll
;
240 const CA_char
*source
;
241 const CA_char
*target
;
245 StrcollUTF8_2::StrcollUTF8_2(const UCollator
* coll
, const CA_char
* source
, const CA_char
* target
, UBool useLen
)
253 StrcollUTF8_2::~StrcollUTF8_2()
257 void StrcollUTF8_2::call(UErrorCode
* status
)
259 if (U_FAILURE(*status
)) return;
261 // call strcoll for two strings at the same index
262 if (source
->count
< target
->count
) {
263 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
265 for (int32_t i
= 0; U_SUCCESS(*status
) && i
< source
->count
; i
++) {
266 int32_t srcLen
= useLen
? source
->lengthOf(i
) : -1;
267 int32_t tgtLen
= useLen
? target
->lengthOf(i
) : -1;
268 ucol_strcollUTF8(coll
, source
->dataOf(i
), srcLen
, target
->dataOf(i
), tgtLen
, status
);
273 long StrcollUTF8_2::getOperationsPerIteration()
275 return source
->count
;
279 // Test case taking a single test data array, calling ucol_getSortKey for each
281 class GetSortKey
: public UPerfFunction
284 GetSortKey(const UCollator
* coll
, const CA_uchar
* source
, UBool useLen
);
286 virtual void call(UErrorCode
* status
);
287 virtual long getOperationsPerIteration();
290 const UCollator
*coll
;
291 const CA_uchar
*source
;
295 GetSortKey::GetSortKey(const UCollator
* coll
, const CA_uchar
* source
, UBool useLen
)
302 GetSortKey::~GetSortKey()
306 #define KEY_BUF_SIZE 512
308 void GetSortKey::call(UErrorCode
* status
)
310 if (U_FAILURE(*status
)) return;
312 uint8_t key
[KEY_BUF_SIZE
];
316 for (int32_t i
= 0; i
< source
->count
; i
++) {
317 len
= ucol_getSortKey(coll
, source
->dataOf(i
), source
->lengthOf(i
), key
, KEY_BUF_SIZE
);
320 for (int32_t i
= 0; i
< source
->count
; i
++) {
321 len
= ucol_getSortKey(coll
, source
->dataOf(i
), -1, key
, KEY_BUF_SIZE
);
326 long GetSortKey::getOperationsPerIteration()
328 return source
->count
;
332 // Test case taking a single test data array in UTF-16, calling ucol_nextSortKeyPart for each for the
335 class NextSortKeyPart
: public UPerfFunction
338 NextSortKeyPart(const UCollator
* coll
, const CA_uchar
* source
, int32_t bufSize
, int32_t maxIteration
= -1);
340 virtual void call(UErrorCode
* status
);
341 virtual long getOperationsPerIteration();
342 virtual long getEventsPerIteration();
345 const UCollator
*coll
;
346 const CA_uchar
*source
;
348 int32_t maxIteration
;
352 // Note: maxIteration = -1 -> repeat until the end of collation key
353 NextSortKeyPart::NextSortKeyPart(const UCollator
* coll
, const CA_uchar
* source
, int32_t bufSize
, int32_t maxIteration
/* = -1 */)
357 maxIteration(maxIteration
),
362 NextSortKeyPart::~NextSortKeyPart()
366 void NextSortKeyPart::call(UErrorCode
* status
)
368 if (U_FAILURE(*status
)) return;
370 uint8_t *part
= (uint8_t *)malloc(bufSize
);
375 for (int i
= 0; i
< source
->count
&& U_SUCCESS(*status
); i
++) {
376 uiter_setString(&iter
, source
->dataOf(i
), source
->lengthOf(i
));
379 int32_t partLen
= bufSize
;
380 for (int32_t n
= 0; U_SUCCESS(*status
) && partLen
== bufSize
&& (maxIteration
< 0 || n
< maxIteration
); n
++) {
381 partLen
= ucol_nextSortKeyPart(coll
, &iter
, state
, part
, bufSize
, status
);
388 long NextSortKeyPart::getOperationsPerIteration()
390 return source
->count
;
393 long NextSortKeyPart::getEventsPerIteration()
399 // Test case taking a single test data array in UTF-8, calling ucol_nextSortKeyPart for each for the
402 class NextSortKeyPartUTF8
: public UPerfFunction
405 NextSortKeyPartUTF8(const UCollator
* coll
, const CA_char
* source
, int32_t bufSize
, int32_t maxIteration
= -1);
406 ~NextSortKeyPartUTF8();
407 virtual void call(UErrorCode
* status
);
408 virtual long getOperationsPerIteration();
409 virtual long getEventsPerIteration();
412 const UCollator
*coll
;
413 const CA_char
*source
;
415 int32_t maxIteration
;
419 // Note: maxIteration = -1 -> repeat until the end of collation key
420 NextSortKeyPartUTF8::NextSortKeyPartUTF8(const UCollator
* coll
, const CA_char
* source
, int32_t bufSize
, int32_t maxIteration
/* = -1 */)
424 maxIteration(maxIteration
),
429 NextSortKeyPartUTF8::~NextSortKeyPartUTF8()
433 void NextSortKeyPartUTF8::call(UErrorCode
* status
)
435 if (U_FAILURE(*status
)) return;
437 uint8_t *part
= (uint8_t *)malloc(bufSize
);
442 for (int i
= 0; i
< source
->count
&& U_SUCCESS(*status
); i
++) {
443 uiter_setUTF8(&iter
, source
->dataOf(i
), source
->lengthOf(i
));
446 int32_t partLen
= bufSize
;
447 for (int32_t n
= 0; U_SUCCESS(*status
) && partLen
== bufSize
&& (maxIteration
< 0 || n
< maxIteration
); n
++) {
448 partLen
= ucol_nextSortKeyPart(coll
, &iter
, state
, part
, bufSize
, status
);
455 long NextSortKeyPartUTF8::getOperationsPerIteration()
457 return source
->count
;
460 long NextSortKeyPartUTF8::getEventsPerIteration()
465 // CPP API test cases
468 // Test case taking a single test data array, calling Collator::compare by permuting the test data
470 class CppCompare
: public UPerfFunction
473 CppCompare(const Collator
* coll
, const CA_uchar
* source
, UBool useLen
);
475 virtual void call(UErrorCode
* status
);
476 virtual long getOperationsPerIteration();
479 const Collator
*coll
;
480 const CA_uchar
*source
;
482 int32_t maxTestStrings
;
485 CppCompare::CppCompare(const Collator
* coll
, const CA_uchar
* source
, UBool useLen
)
490 maxTestStrings
= source
->count
> MAX_TEST_STRINGS_FOR_PERMUTING
? MAX_TEST_STRINGS_FOR_PERMUTING
: source
->count
;
493 CppCompare::~CppCompare()
497 void CppCompare::call(UErrorCode
* status
) {
498 if (U_FAILURE(*status
)) return;
500 // call compare for permutation of test data
501 int32_t divisor
= source
->count
/ maxTestStrings
;
502 int32_t srcLen
, tgtLen
;
504 for (int32_t i
= 0, numTestStringsI
= 0; i
< source
->count
&& numTestStringsI
< maxTestStrings
; i
++) {
505 if (i
% divisor
) continue;
507 srcLen
= useLen
? source
->lengthOf(i
) : -1;
508 for (int32_t j
= 0, numTestStringsJ
= 0; j
< source
->count
&& numTestStringsJ
< maxTestStrings
; j
++) {
509 if (j
% divisor
) continue;
511 tgtLen
= useLen
? source
->lengthOf(j
) : -1;
512 cmp
+= coll
->compare(source
->dataOf(i
), srcLen
, source
->dataOf(j
), tgtLen
);
515 // At the end, cmp must be 0
517 *status
= U_INTERNAL_PROGRAM_ERROR
;
521 long CppCompare::getOperationsPerIteration()
523 return maxTestStrings
* maxTestStrings
;
527 // Test case taking two test data arrays, calling Collator::compare for strings at a same index
529 class CppCompare_2
: public UPerfFunction
532 CppCompare_2(const Collator
* coll
, const CA_uchar
* source
, const CA_uchar
* target
, UBool useLen
);
534 virtual void call(UErrorCode
* status
);
535 virtual long getOperationsPerIteration();
538 const Collator
*coll
;
539 const CA_uchar
*source
;
540 const CA_uchar
*target
;
544 CppCompare_2::CppCompare_2(const Collator
* coll
, const CA_uchar
* source
, const CA_uchar
* target
, UBool useLen
)
552 CppCompare_2::~CppCompare_2()
556 void CppCompare_2::call(UErrorCode
* status
) {
557 if (U_FAILURE(*status
)) return;
559 // call strcoll for two strings at the same index
560 if (source
->count
< target
->count
) {
561 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
563 for (int32_t i
= 0; i
< source
->count
; i
++) {
564 int32_t srcLen
= useLen
? source
->lengthOf(i
) : -1;
565 int32_t tgtLen
= useLen
? target
->lengthOf(i
) : -1;
566 coll
->compare(source
->dataOf(i
), srcLen
, target
->dataOf(i
), tgtLen
);
571 long CppCompare_2::getOperationsPerIteration()
573 return source
->count
;
578 // Test case taking a single test data array, calling Collator::compareUTF8 by permuting the test data
580 class CppCompareUTF8
: public UPerfFunction
583 CppCompareUTF8(const Collator
* coll
, const CA_char
* source
, UBool useLen
);
585 virtual void call(UErrorCode
* status
);
586 virtual long getOperationsPerIteration();
589 const Collator
*coll
;
590 const CA_char
*source
;
592 int32_t maxTestStrings
;
595 CppCompareUTF8::CppCompareUTF8(const Collator
* coll
, const CA_char
* source
, UBool useLen
)
600 maxTestStrings
= source
->count
> MAX_TEST_STRINGS_FOR_PERMUTING
? MAX_TEST_STRINGS_FOR_PERMUTING
: source
->count
;
603 CppCompareUTF8::~CppCompareUTF8()
607 void CppCompareUTF8::call(UErrorCode
* status
) {
608 if (U_FAILURE(*status
)) return;
610 // call compareUTF8 for all permutations
611 int32_t divisor
= source
->count
/ maxTestStrings
;
612 StringPiece src
, tgt
;
614 for (int32_t i
= 0, numTestStringsI
= 0; U_SUCCESS(*status
) && i
< source
->count
&& numTestStringsI
< maxTestStrings
; i
++) {
615 if (i
% divisor
) continue;
619 src
.set(source
->dataOf(i
), source
->lengthOf(i
));
621 src
.set(source
->dataOf(i
));
623 for (int32_t j
= 0, numTestStringsJ
= 0; U_SUCCESS(*status
) && j
< source
->count
&& numTestStringsJ
< maxTestStrings
; j
++) {
624 if (j
% divisor
) continue;
628 tgt
.set(source
->dataOf(i
), source
->lengthOf(i
));
630 tgt
.set(source
->dataOf(i
));
632 cmp
+= coll
->compareUTF8(src
, tgt
, *status
);
635 // At the end, cmp must be 0
637 *status
= U_INTERNAL_PROGRAM_ERROR
;
641 long CppCompareUTF8::getOperationsPerIteration()
643 return maxTestStrings
* maxTestStrings
;
648 // Test case taking two test data arrays, calling Collator::compareUTF8 for strings at a same index
650 class CppCompareUTF8_2
: public UPerfFunction
653 CppCompareUTF8_2(const Collator
* coll
, const CA_char
* source
, const CA_char
* target
, UBool useLen
);
655 virtual void call(UErrorCode
* status
);
656 virtual long getOperationsPerIteration();
659 const Collator
*coll
;
660 const CA_char
*source
;
661 const CA_char
*target
;
665 CppCompareUTF8_2::CppCompareUTF8_2(const Collator
* coll
, const CA_char
* source
, const CA_char
* target
, UBool useLen
)
673 CppCompareUTF8_2::~CppCompareUTF8_2()
677 void CppCompareUTF8_2::call(UErrorCode
* status
) {
678 if (U_FAILURE(*status
)) return;
680 // call strcoll for two strings at the same index
681 StringPiece src
, tgt
;
682 if (source
->count
< target
->count
) {
683 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
685 for (int32_t i
= 0; U_SUCCESS(*status
) && i
< source
->count
; i
++) {
687 src
.set(source
->dataOf(i
), source
->lengthOf(i
));
688 tgt
.set(target
->dataOf(i
), target
->lengthOf(i
));
690 src
.set(source
->dataOf(i
));
691 tgt
.set(target
->dataOf(i
));
693 coll
->compareUTF8(src
, tgt
, *status
);
698 long CppCompareUTF8_2::getOperationsPerIteration()
700 return source
->count
;
705 // Test case taking a single test data array, calling Collator::getCollationKey for each
707 class CppGetCollationKey
: public UPerfFunction
710 CppGetCollationKey(const Collator
* coll
, const CA_uchar
* source
, UBool useLen
);
711 ~CppGetCollationKey();
712 virtual void call(UErrorCode
* status
);
713 virtual long getOperationsPerIteration();
716 const Collator
*coll
;
717 const CA_uchar
*source
;
721 CppGetCollationKey::CppGetCollationKey(const Collator
* coll
, const CA_uchar
* source
, UBool useLen
)
728 CppGetCollationKey::~CppGetCollationKey()
732 void CppGetCollationKey::call(UErrorCode
* status
)
734 if (U_FAILURE(*status
)) return;
737 for (int32_t i
= 0; U_SUCCESS(*status
) && i
< source
->count
; i
++) {
738 coll
->getCollationKey(source
->dataOf(i
), source
->lengthOf(i
), key
, *status
);
742 long CppGetCollationKey::getOperationsPerIteration() {
743 return source
->count
;
748 struct CollatorAndCounter
{
749 CollatorAndCounter(const Collator
& coll
) : coll(coll
), ucoll(NULL
), counter(0) {}
750 CollatorAndCounter(const Collator
& coll
, const UCollator
*ucoll
)
751 : coll(coll
), ucoll(ucoll
), counter(0) {}
752 const Collator
& coll
;
753 const UCollator
*ucoll
;
758 UniStrCollatorComparator(const void* context
, const void* left
, const void* right
) {
759 CollatorAndCounter
& cc
= *(CollatorAndCounter
*)context
;
760 const UnicodeString
& leftString
= **(const UnicodeString
**)left
;
761 const UnicodeString
& rightString
= **(const UnicodeString
**)right
;
762 UErrorCode errorCode
= U_ZERO_ERROR
;
764 return cc
.coll
.compare(leftString
, rightString
, errorCode
);
769 class CollPerfFunction
: public UPerfFunction
{
771 CollPerfFunction(const Collator
& coll
, const UCollator
*ucoll
)
772 : coll(coll
), ucoll(ucoll
), ops(0) {}
773 virtual ~CollPerfFunction();
774 /** Calls call() to set the ops field, and returns that. */
775 virtual long getOperationsPerIteration();
778 const Collator
& coll
;
779 const UCollator
*ucoll
;
783 CollPerfFunction::~CollPerfFunction() {}
785 long CollPerfFunction::getOperationsPerIteration() {
786 UErrorCode errorCode
= U_ZERO_ERROR
;
788 return U_SUCCESS(errorCode
) ? ops
: 0;
791 class UniStrCollPerfFunction
: public CollPerfFunction
{
793 UniStrCollPerfFunction(const Collator
& coll
, const UCollator
*ucoll
, const CA_uchar
* data16
)
794 : CollPerfFunction(coll
, ucoll
), d16(data16
),
795 source(new UnicodeString
*[d16
->count
]) {
796 for (int32_t i
= 0; i
< d16
->count
; ++i
) {
797 source
[i
] = new UnicodeString(TRUE
, d16
->dataOf(i
), d16
->lengthOf(i
));
800 virtual ~UniStrCollPerfFunction();
804 UnicodeString
** source
;
807 UniStrCollPerfFunction::~UniStrCollPerfFunction() {
808 for (int32_t i
= 0; i
< d16
->count
; ++i
) {
815 // Test case sorting an array of UnicodeString pointers.
817 class UniStrSort
: public UniStrCollPerfFunction
{
819 UniStrSort(const Collator
& coll
, const UCollator
*ucoll
, const CA_uchar
* data16
)
820 : UniStrCollPerfFunction(coll
, ucoll
, data16
),
821 dest(new UnicodeString
*[d16
->count
]) {}
822 virtual ~UniStrSort();
823 virtual void call(UErrorCode
* status
);
826 UnicodeString
** dest
; // aliases only
829 UniStrSort::~UniStrSort() {
833 void UniStrSort::call(UErrorCode
* status
) {
834 if (U_FAILURE(*status
)) return;
836 CollatorAndCounter
cc(coll
);
837 int32_t count
= d16
->count
;
838 memcpy(dest
, source
, count
* sizeof(UnicodeString
*));
839 uprv_sortArray(dest
, count
, (int32_t)sizeof(UnicodeString
*),
840 UniStrCollatorComparator
, &cc
, TRUE
, status
);
847 StringPieceCollatorComparator(const void* context
, const void* left
, const void* right
) {
848 CollatorAndCounter
& cc
= *(CollatorAndCounter
*)context
;
849 const StringPiece
& leftString
= *(const StringPiece
*)left
;
850 const StringPiece
& rightString
= *(const StringPiece
*)right
;
851 UErrorCode errorCode
= U_ZERO_ERROR
;
853 return cc
.coll
.compareUTF8(leftString
, rightString
, errorCode
);
857 StringPieceUCollatorComparator(const void* context
, const void* left
, const void* right
) {
858 CollatorAndCounter
& cc
= *(CollatorAndCounter
*)context
;
859 const StringPiece
& leftString
= *(const StringPiece
*)left
;
860 const StringPiece
& rightString
= *(const StringPiece
*)right
;
861 UErrorCode errorCode
= U_ZERO_ERROR
;
863 return ucol_strcollUTF8(cc
.ucoll
,
864 leftString
.data(), leftString
.length(),
865 rightString
.data(), rightString
.length(), &errorCode
);
870 class StringPieceCollPerfFunction
: public CollPerfFunction
{
872 StringPieceCollPerfFunction(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
873 : CollPerfFunction(coll
, ucoll
), d8(data8
),
874 source(new StringPiece
[d8
->count
]) {
875 for (int32_t i
= 0; i
< d8
->count
; ++i
) {
876 source
[i
].set(d8
->dataOf(i
), d8
->lengthOf(i
));
879 virtual ~StringPieceCollPerfFunction();
886 StringPieceCollPerfFunction::~StringPieceCollPerfFunction() {
890 class StringPieceSort
: public StringPieceCollPerfFunction
{
892 StringPieceSort(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
893 : StringPieceCollPerfFunction(coll
, ucoll
, data8
),
894 dest(new StringPiece
[d8
->count
]) {}
895 virtual ~StringPieceSort();
901 StringPieceSort::~StringPieceSort() {
906 // Test case sorting an array of UTF-8 StringPiece's with Collator::compareUTF8().
908 class StringPieceSortCpp
: public StringPieceSort
{
910 StringPieceSortCpp(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
911 : StringPieceSort(coll
, ucoll
, data8
) {}
912 virtual ~StringPieceSortCpp();
913 virtual void call(UErrorCode
* status
);
916 StringPieceSortCpp::~StringPieceSortCpp() {}
918 void StringPieceSortCpp::call(UErrorCode
* status
) {
919 if (U_FAILURE(*status
)) return;
921 CollatorAndCounter
cc(coll
);
922 int32_t count
= d8
->count
;
923 memcpy(dest
, source
, count
* sizeof(StringPiece
));
924 uprv_sortArray(dest
, count
, (int32_t)sizeof(StringPiece
),
925 StringPieceCollatorComparator
, &cc
, TRUE
, status
);
930 // Test case sorting an array of UTF-8 StringPiece's with ucol_strcollUTF8().
932 class StringPieceSortC
: public StringPieceSort
{
934 StringPieceSortC(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
935 : StringPieceSort(coll
, ucoll
, data8
) {}
936 virtual ~StringPieceSortC();
937 virtual void call(UErrorCode
* status
);
940 StringPieceSortC::~StringPieceSortC() {}
942 void StringPieceSortC::call(UErrorCode
* status
) {
943 if (U_FAILURE(*status
)) return;
945 CollatorAndCounter
cc(coll
, ucoll
);
946 int32_t count
= d8
->count
;
947 memcpy(dest
, source
, count
* sizeof(StringPiece
));
948 uprv_sortArray(dest
, count
, (int32_t)sizeof(StringPiece
),
949 StringPieceUCollatorComparator
, &cc
, TRUE
, status
);
954 // Test case performing binary searches in a sorted array of UnicodeString pointers.
956 class UniStrBinSearch
: public UniStrCollPerfFunction
{
958 UniStrBinSearch(const Collator
& coll
, const UCollator
*ucoll
, const CA_uchar
* data16
)
959 : UniStrCollPerfFunction(coll
, ucoll
, data16
) {}
960 virtual ~UniStrBinSearch();
961 virtual void call(UErrorCode
* status
);
964 UniStrBinSearch::~UniStrBinSearch() {}
966 void UniStrBinSearch::call(UErrorCode
* status
) {
967 if (U_FAILURE(*status
)) return;
969 CollatorAndCounter
cc(coll
);
970 int32_t count
= d16
->count
;
971 for (int32_t i
= 0; i
< count
; ++i
) {
972 (void)uprv_stableBinarySearch((char *)source
, count
,
973 source
+ i
, (int32_t)sizeof(UnicodeString
*),
974 UniStrCollatorComparator
, &cc
);
979 class StringPieceBinSearch
: public StringPieceCollPerfFunction
{
981 StringPieceBinSearch(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
982 : StringPieceCollPerfFunction(coll
, ucoll
, data8
) {}
983 virtual ~StringPieceBinSearch();
986 StringPieceBinSearch::~StringPieceBinSearch() {}
989 // Test case performing binary searches in a sorted array of UTF-8 StringPiece's
990 // with Collator::compareUTF8().
992 class StringPieceBinSearchCpp
: public StringPieceBinSearch
{
994 StringPieceBinSearchCpp(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
995 : StringPieceBinSearch(coll
, ucoll
, data8
) {}
996 virtual ~StringPieceBinSearchCpp();
997 virtual void call(UErrorCode
* status
);
1000 StringPieceBinSearchCpp::~StringPieceBinSearchCpp() {}
1002 void StringPieceBinSearchCpp::call(UErrorCode
* status
) {
1003 if (U_FAILURE(*status
)) return;
1005 CollatorAndCounter
cc(coll
);
1006 int32_t count
= d8
->count
;
1007 for (int32_t i
= 0; i
< count
; ++i
) {
1008 (void)uprv_stableBinarySearch((char *)source
, count
,
1009 source
+ i
, (int32_t)sizeof(StringPiece
),
1010 StringPieceCollatorComparator
, &cc
);
1016 // Test case performing binary searches in a sorted array of UTF-8 StringPiece's
1017 // with ucol_strcollUTF8().
1019 class StringPieceBinSearchC
: public StringPieceBinSearch
{
1021 StringPieceBinSearchC(const Collator
& coll
, const UCollator
*ucoll
, const CA_char
* data8
)
1022 : StringPieceBinSearch(coll
, ucoll
, data8
) {}
1023 virtual ~StringPieceBinSearchC();
1024 virtual void call(UErrorCode
* status
);
1027 StringPieceBinSearchC::~StringPieceBinSearchC() {}
1029 void StringPieceBinSearchC::call(UErrorCode
* status
) {
1030 if (U_FAILURE(*status
)) return;
1032 CollatorAndCounter
cc(coll
, ucoll
);
1033 int32_t count
= d8
->count
;
1034 for (int32_t i
= 0; i
< count
; ++i
) {
1035 (void)uprv_stableBinarySearch((char *)source
, count
,
1036 source
+ i
, (int32_t)sizeof(StringPiece
),
1037 StringPieceUCollatorComparator
, &cc
);
1043 class CollPerf2Test
: public UPerfTest
1046 CollPerf2Test(int32_t argc
, const char *argv
[], UErrorCode
&status
);
1048 virtual UPerfFunction
* runIndexedTest(
1049 int32_t index
, UBool exec
, const char *&name
, char *par
= NULL
);
1059 CA_uchar
* modData16
;
1062 CA_uchar
* sortedData16
;
1063 CA_char
* sortedData8
;
1065 CA_uchar
* randomData16
;
1066 CA_char
* randomData8
;
1068 const CA_uchar
* getData16(UErrorCode
&status
);
1069 const CA_char
* getData8(UErrorCode
&status
);
1071 const CA_uchar
* getModData16(UErrorCode
&status
);
1072 const CA_char
* getModData8(UErrorCode
&status
);
1074 const CA_uchar
* getSortedData16(UErrorCode
&status
);
1075 const CA_char
* getSortedData8(UErrorCode
&status
);
1077 const CA_uchar
* getRandomData16(UErrorCode
&status
);
1078 const CA_char
* getRandomData8(UErrorCode
&status
);
1080 static CA_uchar
* sortData16(
1081 const CA_uchar
* d16
,
1082 UComparator
*cmp
, const void *context
,
1083 UErrorCode
&status
);
1084 static CA_char
* getData8FromData16(const CA_uchar
* d16
, UErrorCode
&status
);
1086 UPerfFunction
* TestStrcoll();
1087 UPerfFunction
* TestStrcollNull();
1088 UPerfFunction
* TestStrcollSimilar();
1090 UPerfFunction
* TestStrcollUTF8();
1091 UPerfFunction
* TestStrcollUTF8Null();
1092 UPerfFunction
* TestStrcollUTF8Similar();
1094 UPerfFunction
* TestGetSortKey();
1095 UPerfFunction
* TestGetSortKeyNull();
1097 UPerfFunction
* TestNextSortKeyPart_4All();
1098 UPerfFunction
* TestNextSortKeyPart_4x2();
1099 UPerfFunction
* TestNextSortKeyPart_4x4();
1100 UPerfFunction
* TestNextSortKeyPart_4x8();
1101 UPerfFunction
* TestNextSortKeyPart_32All();
1102 UPerfFunction
* TestNextSortKeyPart_32x2();
1104 UPerfFunction
* TestNextSortKeyPartUTF8_4All();
1105 UPerfFunction
* TestNextSortKeyPartUTF8_4x2();
1106 UPerfFunction
* TestNextSortKeyPartUTF8_4x4();
1107 UPerfFunction
* TestNextSortKeyPartUTF8_4x8();
1108 UPerfFunction
* TestNextSortKeyPartUTF8_32All();
1109 UPerfFunction
* TestNextSortKeyPartUTF8_32x2();
1111 UPerfFunction
* TestCppCompare();
1112 UPerfFunction
* TestCppCompareNull();
1113 UPerfFunction
* TestCppCompareSimilar();
1115 UPerfFunction
* TestCppCompareUTF8();
1116 UPerfFunction
* TestCppCompareUTF8Null();
1117 UPerfFunction
* TestCppCompareUTF8Similar();
1119 UPerfFunction
* TestCppGetCollationKey();
1120 UPerfFunction
* TestCppGetCollationKeyNull();
1122 UPerfFunction
* TestUniStrSort();
1123 UPerfFunction
* TestStringPieceSortCpp();
1124 UPerfFunction
* TestStringPieceSortC();
1126 UPerfFunction
* TestUniStrBinSearch();
1127 UPerfFunction
* TestStringPieceBinSearchCpp();
1128 UPerfFunction
* TestStringPieceBinSearchC();
1131 CollPerf2Test::CollPerf2Test(int32_t argc
, const char *argv
[], UErrorCode
&status
) :
1132 UPerfTest(argc
, argv
, status
),
1145 if (U_FAILURE(status
)) {
1149 if (locale
== NULL
){
1153 // Set up an ICU collator.
1154 // Starting with ICU 54 (ticket #8260), this supports standard collation locale keywords.
1155 coll
= ucol_open(locale
, &status
);
1156 collObj
= Collator::createInstance(locale
, status
);
1159 CollPerf2Test::~CollPerf2Test()
1168 delete sortedData16
;
1170 delete randomData16
;
1174 #define MAX_NUM_DATA 10000
1176 const CA_uchar
* CollPerf2Test::getData16(UErrorCode
&status
)
1178 if (U_FAILURE(status
)) return NULL
;
1179 if (data16
) return data16
;
1181 CA_uchar
* d16
= new CA_uchar();
1182 const UChar
*line
= NULL
;
1184 int32_t numData
= 0;
1187 line
= ucbuf_readline(ucharBuf
, &len
, &status
);
1188 if (line
== NULL
|| U_FAILURE(status
)) break;
1190 // Refer to the source code of ucbuf_readline()
1191 // 1. 'len' includes the line terminal symbols
1192 // 2. The length of the line terminal symbols is only one character
1193 // 3. The Windows CR LF line terminal symbols will be converted to CR
1195 if (len
== 1 || line
[0] == 0x23 /* '#' */) {
1196 continue; // skip empty/comment line
1198 d16
->append_one(len
);
1199 UChar
*p
= d16
->last();
1200 u_memcpy(p
, line
, len
- 1); // exclude the CR
1201 p
[len
- 1] = 0; // NUL-terminate
1204 if (numData
>= MAX_NUM_DATA
) break;
1208 if (U_SUCCESS(status
)) {
1217 const CA_char
* CollPerf2Test::getData8(UErrorCode
&status
)
1219 if (U_FAILURE(status
)) return NULL
;
1220 if (data8
) return data8
;
1221 return data8
= getData8FromData16(getData16(status
), status
);
1224 const CA_uchar
* CollPerf2Test::getModData16(UErrorCode
&status
)
1226 if (U_FAILURE(status
)) return NULL
;
1227 if (modData16
) return modData16
;
1229 const CA_uchar
* d16
= getData16(status
);
1230 if (U_FAILURE(status
)) return NULL
;
1232 CA_uchar
* modData16
= new CA_uchar();
1234 for (int32_t i
= 0; i
< d16
->count
; i
++) {
1235 const UChar
*s
= d16
->dataOf(i
);
1236 int32_t len
= d16
->lengthOf(i
) + 1; // including NULL terminator
1238 modData16
->append_one(len
);
1239 u_memcpy(modData16
->last(), s
, len
);
1241 // replacing the last character with a different character
1242 UChar
*lastChar
= &modData16
->last()[len
-2];
1243 for (int32_t j
= i
+ 1; j
!= i
; j
++) {
1244 if (j
>= d16
->count
) {
1247 const UChar
*s1
= d16
->dataOf(j
);
1248 UChar lastChar1
= s1
[d16
->lengthOf(j
) - 1];
1249 if (*lastChar
!= lastChar1
) {
1250 *lastChar
= lastChar1
;
1259 const CA_char
* CollPerf2Test::getModData8(UErrorCode
&status
)
1261 if (U_FAILURE(status
)) return NULL
;
1262 if (modData8
) return modData8
;
1263 return modData8
= getData8FromData16(getModData16(status
), status
);
1268 struct ArrayAndColl
{
1269 ArrayAndColl(const CA_uchar
* a
, const Collator
& c
) : d16(a
), coll(c
) {}
1270 const CA_uchar
* d16
;
1271 const Collator
& coll
;
1275 U16CollatorComparator(const void* context
, const void* left
, const void* right
) {
1276 const ArrayAndColl
& ac
= *(const ArrayAndColl
*)context
;
1277 const CA_uchar
* d16
= ac
.d16
;
1278 int32_t leftIndex
= *(const int32_t*)left
;
1279 int32_t rightIndex
= *(const int32_t*)right
;
1280 UErrorCode errorCode
= U_ZERO_ERROR
;
1281 return ac
.coll
.compare(d16
->dataOf(leftIndex
), d16
->lengthOf(leftIndex
),
1282 d16
->dataOf(rightIndex
), d16
->lengthOf(rightIndex
),
1287 U16HashComparator(const void* context
, const void* left
, const void* right
) {
1288 const CA_uchar
* d16
= (const CA_uchar
*)context
;
1289 int32_t leftIndex
= *(const int32_t*)left
;
1290 int32_t rightIndex
= *(const int32_t*)right
;
1291 int32_t leftHash
= ustr_hashUCharsN(d16
->dataOf(leftIndex
), d16
->lengthOf(leftIndex
));
1292 int32_t rightHash
= ustr_hashUCharsN(d16
->dataOf(rightIndex
), d16
->lengthOf(rightIndex
));
1293 return leftHash
< rightHash
? -1 : leftHash
== rightHash
? 0 : 1;
1298 const CA_uchar
* CollPerf2Test::getSortedData16(UErrorCode
&status
) {
1299 if (U_FAILURE(status
)) return NULL
;
1300 if (sortedData16
) return sortedData16
;
1302 ArrayAndColl
ac(getData16(status
), *collObj
);
1303 return sortedData16
= sortData16(ac
.d16
, U16CollatorComparator
, &ac
, status
);
1306 const CA_char
* CollPerf2Test::getSortedData8(UErrorCode
&status
) {
1307 if (U_FAILURE(status
)) return NULL
;
1308 if (sortedData8
) return sortedData8
;
1309 return sortedData8
= getData8FromData16(getSortedData16(status
), status
);
1312 const CA_uchar
* CollPerf2Test::getRandomData16(UErrorCode
&status
) {
1313 if (U_FAILURE(status
)) return NULL
;
1314 if (randomData16
) return randomData16
;
1316 // Sort the strings by their hash codes, which should be a reasonably pseudo-random order.
1317 const CA_uchar
* d16
= getData16(status
);
1318 return randomData16
= sortData16(d16
, U16HashComparator
, d16
, status
);
1321 const CA_char
* CollPerf2Test::getRandomData8(UErrorCode
&status
) {
1322 if (U_FAILURE(status
)) return NULL
;
1323 if (randomData8
) return randomData8
;
1324 return randomData8
= getData8FromData16(getRandomData16(status
), status
);
1327 CA_uchar
* CollPerf2Test::sortData16(const CA_uchar
* d16
,
1328 UComparator
*cmp
, const void *context
,
1329 UErrorCode
&status
) {
1330 if (U_FAILURE(status
)) return NULL
;
1332 LocalArray
<int32_t> indexes(new int32_t[d16
->count
]);
1333 for (int32_t i
= 0; i
< d16
->count
; ++i
) {
1336 uprv_sortArray(indexes
.getAlias(), d16
->count
, 4, cmp
, context
, TRUE
, &status
);
1337 if (U_FAILURE(status
)) return NULL
;
1339 // Copy the strings in sorted order into a new array.
1340 LocalPointer
<CA_uchar
> newD16(new CA_uchar());
1341 for (int32_t i
= 0; i
< d16
->count
; i
++) {
1342 int32_t j
= indexes
[i
];
1343 const UChar
* s
= d16
->dataOf(j
);
1344 int32_t len
= d16
->lengthOf(j
);
1345 int32_t capacity
= len
+ 1; // including NULL terminator
1346 newD16
->append_one(capacity
);
1347 u_memcpy(newD16
->last(), s
, capacity
);
1350 if (U_SUCCESS(status
)) {
1351 return newD16
.orphan();
1357 CA_char
* CollPerf2Test::getData8FromData16(const CA_uchar
* d16
, UErrorCode
&status
) {
1358 if (U_FAILURE(status
)) return NULL
;
1360 // UTF-16 -> UTF-8 conversion
1361 LocalPointer
<CA_char
> d8(new CA_char());
1362 for (int32_t i
= 0; i
< d16
->count
; i
++) {
1363 const UChar
*s16
= d16
->dataOf(i
);
1364 int32_t length16
= d16
->lengthOf(i
);
1366 // get length in UTF-8
1368 u_strToUTF8(NULL
, 0, &length8
, s16
, length16
, &status
);
1369 if (status
== U_BUFFER_OVERFLOW_ERROR
|| status
== U_ZERO_ERROR
){
1370 status
= U_ZERO_ERROR
;
1374 int32_t capacity8
= length8
+ 1; // plus terminal NULL
1375 d8
->append_one(capacity8
);
1378 u_strToUTF8(d8
->last(), capacity8
, NULL
, s16
, length16
, &status
);
1379 if (U_FAILURE(status
)) break;
1382 if (U_SUCCESS(status
)) {
1390 CollPerf2Test::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
/*= NULL*/)
1393 TESTCASE_AUTO_BEGIN
;
1395 TESTCASE_AUTO(TestStrcoll
);
1396 TESTCASE_AUTO(TestStrcollNull
);
1397 TESTCASE_AUTO(TestStrcollSimilar
);
1399 TESTCASE_AUTO(TestStrcollUTF8
);
1400 TESTCASE_AUTO(TestStrcollUTF8Null
);
1401 TESTCASE_AUTO(TestStrcollUTF8Similar
);
1403 TESTCASE_AUTO(TestGetSortKey
);
1404 TESTCASE_AUTO(TestGetSortKeyNull
);
1406 TESTCASE_AUTO(TestNextSortKeyPart_4All
);
1407 TESTCASE_AUTO(TestNextSortKeyPart_4x4
);
1408 TESTCASE_AUTO(TestNextSortKeyPart_4x8
);
1409 TESTCASE_AUTO(TestNextSortKeyPart_32All
);
1410 TESTCASE_AUTO(TestNextSortKeyPart_32x2
);
1412 TESTCASE_AUTO(TestNextSortKeyPartUTF8_4All
);
1413 TESTCASE_AUTO(TestNextSortKeyPartUTF8_4x4
);
1414 TESTCASE_AUTO(TestNextSortKeyPartUTF8_4x8
);
1415 TESTCASE_AUTO(TestNextSortKeyPartUTF8_32All
);
1416 TESTCASE_AUTO(TestNextSortKeyPartUTF8_32x2
);
1418 TESTCASE_AUTO(TestCppCompare
);
1419 TESTCASE_AUTO(TestCppCompareNull
);
1420 TESTCASE_AUTO(TestCppCompareSimilar
);
1422 TESTCASE_AUTO(TestCppCompareUTF8
);
1423 TESTCASE_AUTO(TestCppCompareUTF8Null
);
1424 TESTCASE_AUTO(TestCppCompareUTF8Similar
);
1426 TESTCASE_AUTO(TestCppGetCollationKey
);
1427 TESTCASE_AUTO(TestCppGetCollationKeyNull
);
1429 TESTCASE_AUTO(TestUniStrSort
);
1430 TESTCASE_AUTO(TestStringPieceSortCpp
);
1431 TESTCASE_AUTO(TestStringPieceSortC
);
1433 TESTCASE_AUTO(TestUniStrBinSearch
);
1434 TESTCASE_AUTO(TestStringPieceBinSearchCpp
);
1435 TESTCASE_AUTO(TestStringPieceBinSearchC
);
1443 UPerfFunction
* CollPerf2Test::TestStrcoll()
1445 UErrorCode status
= U_ZERO_ERROR
;
1446 Strcoll
*testCase
= new Strcoll(coll
, getData16(status
), TRUE
/* useLen */);
1447 if (U_FAILURE(status
)) {
1454 UPerfFunction
* CollPerf2Test::TestStrcollNull()
1456 UErrorCode status
= U_ZERO_ERROR
;
1457 Strcoll
*testCase
= new Strcoll(coll
, getData16(status
), FALSE
/* useLen */);
1458 if (U_FAILURE(status
)) {
1465 UPerfFunction
* CollPerf2Test::TestStrcollSimilar()
1467 UErrorCode status
= U_ZERO_ERROR
;
1468 Strcoll_2
*testCase
= new Strcoll_2(coll
, getData16(status
), getModData16(status
), TRUE
/* useLen */);
1469 if (U_FAILURE(status
)) {
1476 UPerfFunction
* CollPerf2Test::TestStrcollUTF8()
1478 UErrorCode status
= U_ZERO_ERROR
;
1479 StrcollUTF8
*testCase
= new StrcollUTF8(coll
, getData8(status
), TRUE
/* useLen */);
1480 if (U_FAILURE(status
)) {
1487 UPerfFunction
* CollPerf2Test::TestStrcollUTF8Null()
1489 UErrorCode status
= U_ZERO_ERROR
;
1490 StrcollUTF8
*testCase
= new StrcollUTF8(coll
, getData8(status
),FALSE
/* useLen */);
1491 if (U_FAILURE(status
)) {
1498 UPerfFunction
* CollPerf2Test::TestStrcollUTF8Similar()
1500 UErrorCode status
= U_ZERO_ERROR
;
1501 StrcollUTF8_2
*testCase
= new StrcollUTF8_2(coll
, getData8(status
), getModData8(status
), TRUE
/* useLen */);
1502 if (U_FAILURE(status
)) {
1509 UPerfFunction
* CollPerf2Test::TestGetSortKey()
1511 UErrorCode status
= U_ZERO_ERROR
;
1512 GetSortKey
*testCase
= new GetSortKey(coll
, getData16(status
), TRUE
/* useLen */);
1513 if (U_FAILURE(status
)) {
1520 UPerfFunction
* CollPerf2Test::TestGetSortKeyNull()
1522 UErrorCode status
= U_ZERO_ERROR
;
1523 GetSortKey
*testCase
= new GetSortKey(coll
, getData16(status
), FALSE
/* useLen */);
1524 if (U_FAILURE(status
)) {
1531 UPerfFunction
* CollPerf2Test::TestNextSortKeyPart_4All()
1533 UErrorCode status
= U_ZERO_ERROR
;
1534 NextSortKeyPart
*testCase
= new NextSortKeyPart(coll
, getData16(status
), 4 /* bufSize */);
1535 if (U_FAILURE(status
)) {
1542 UPerfFunction
* CollPerf2Test::TestNextSortKeyPart_4x4()
1544 UErrorCode status
= U_ZERO_ERROR
;
1545 NextSortKeyPart
*testCase
= new NextSortKeyPart(coll
, getData16(status
), 4 /* bufSize */, 4 /* maxIteration */);
1546 if (U_FAILURE(status
)) {
1553 UPerfFunction
* CollPerf2Test::TestNextSortKeyPart_4x8()
1555 UErrorCode status
= U_ZERO_ERROR
;
1556 NextSortKeyPart
*testCase
= new NextSortKeyPart(coll
, getData16(status
), 4 /* bufSize */, 8 /* maxIteration */);
1557 if (U_FAILURE(status
)) {
1564 UPerfFunction
* CollPerf2Test::TestNextSortKeyPart_32All()
1566 UErrorCode status
= U_ZERO_ERROR
;
1567 NextSortKeyPart
*testCase
= new NextSortKeyPart(coll
, getData16(status
), 32 /* bufSize */);
1568 if (U_FAILURE(status
)) {
1575 UPerfFunction
* CollPerf2Test::TestNextSortKeyPart_32x2()
1577 UErrorCode status
= U_ZERO_ERROR
;
1578 NextSortKeyPart
*testCase
= new NextSortKeyPart(coll
, getData16(status
), 32 /* bufSize */, 2 /* maxIteration */);
1579 if (U_FAILURE(status
)) {
1586 UPerfFunction
* CollPerf2Test::TestNextSortKeyPartUTF8_4All()
1588 UErrorCode status
= U_ZERO_ERROR
;
1589 NextSortKeyPartUTF8
*testCase
= new NextSortKeyPartUTF8(coll
, getData8(status
), 4 /* bufSize */);
1590 if (U_FAILURE(status
)) {
1597 UPerfFunction
* CollPerf2Test::TestNextSortKeyPartUTF8_4x4()
1599 UErrorCode status
= U_ZERO_ERROR
;
1600 NextSortKeyPartUTF8
*testCase
= new NextSortKeyPartUTF8(coll
, getData8(status
), 4 /* bufSize */, 4 /* maxIteration */);
1601 if (U_FAILURE(status
)) {
1608 UPerfFunction
* CollPerf2Test::TestNextSortKeyPartUTF8_4x8()
1610 UErrorCode status
= U_ZERO_ERROR
;
1611 NextSortKeyPartUTF8
*testCase
= new NextSortKeyPartUTF8(coll
, getData8(status
), 4 /* bufSize */, 8 /* maxIteration */);
1612 if (U_FAILURE(status
)) {
1619 UPerfFunction
* CollPerf2Test::TestNextSortKeyPartUTF8_32All()
1621 UErrorCode status
= U_ZERO_ERROR
;
1622 NextSortKeyPartUTF8
*testCase
= new NextSortKeyPartUTF8(coll
, getData8(status
), 32 /* bufSize */);
1623 if (U_FAILURE(status
)) {
1630 UPerfFunction
* CollPerf2Test::TestNextSortKeyPartUTF8_32x2()
1632 UErrorCode status
= U_ZERO_ERROR
;
1633 NextSortKeyPartUTF8
*testCase
= new NextSortKeyPartUTF8(coll
, getData8(status
), 32 /* bufSize */, 2 /* maxIteration */);
1634 if (U_FAILURE(status
)) {
1641 UPerfFunction
* CollPerf2Test::TestCppCompare()
1643 UErrorCode status
= U_ZERO_ERROR
;
1644 CppCompare
*testCase
= new CppCompare(collObj
, getData16(status
), TRUE
/* useLen */);
1645 if (U_FAILURE(status
)) {
1652 UPerfFunction
* CollPerf2Test::TestCppCompareNull()
1654 UErrorCode status
= U_ZERO_ERROR
;
1655 CppCompare
*testCase
= new CppCompare(collObj
, getData16(status
), FALSE
/* useLen */);
1656 if (U_FAILURE(status
)) {
1663 UPerfFunction
* CollPerf2Test::TestCppCompareSimilar()
1665 UErrorCode status
= U_ZERO_ERROR
;
1666 CppCompare_2
*testCase
= new CppCompare_2(collObj
, getData16(status
), getModData16(status
), TRUE
/* useLen */);
1667 if (U_FAILURE(status
)) {
1674 UPerfFunction
* CollPerf2Test::TestCppCompareUTF8()
1676 UErrorCode status
= U_ZERO_ERROR
;
1677 CppCompareUTF8
*testCase
= new CppCompareUTF8(collObj
, getData8(status
), TRUE
/* useLen */);
1678 if (U_FAILURE(status
)) {
1685 UPerfFunction
* CollPerf2Test::TestCppCompareUTF8Null()
1687 UErrorCode status
= U_ZERO_ERROR
;
1688 CppCompareUTF8
*testCase
= new CppCompareUTF8(collObj
, getData8(status
), FALSE
/* useLen */);
1689 if (U_FAILURE(status
)) {
1696 UPerfFunction
* CollPerf2Test::TestCppCompareUTF8Similar()
1698 UErrorCode status
= U_ZERO_ERROR
;
1699 CppCompareUTF8_2
*testCase
= new CppCompareUTF8_2(collObj
, getData8(status
), getModData8(status
), TRUE
/* useLen */);
1700 if (U_FAILURE(status
)) {
1707 UPerfFunction
* CollPerf2Test::TestCppGetCollationKey()
1709 UErrorCode status
= U_ZERO_ERROR
;
1710 CppGetCollationKey
*testCase
= new CppGetCollationKey(collObj
, getData16(status
), TRUE
/* useLen */);
1711 if (U_FAILURE(status
)) {
1718 UPerfFunction
* CollPerf2Test::TestCppGetCollationKeyNull()
1720 UErrorCode status
= U_ZERO_ERROR
;
1721 CppGetCollationKey
*testCase
= new CppGetCollationKey(collObj
, getData16(status
), FALSE
/* useLen */);
1722 if (U_FAILURE(status
)) {
1729 UPerfFunction
* CollPerf2Test::TestUniStrSort() {
1730 UErrorCode status
= U_ZERO_ERROR
;
1731 UPerfFunction
*testCase
= new UniStrSort(*collObj
, coll
, getRandomData16(status
));
1732 if (U_FAILURE(status
)) {
1739 UPerfFunction
* CollPerf2Test::TestStringPieceSortCpp() {
1740 UErrorCode status
= U_ZERO_ERROR
;
1741 UPerfFunction
*testCase
= new StringPieceSortCpp(*collObj
, coll
, getRandomData8(status
));
1742 if (U_FAILURE(status
)) {
1749 UPerfFunction
* CollPerf2Test::TestStringPieceSortC() {
1750 UErrorCode status
= U_ZERO_ERROR
;
1751 UPerfFunction
*testCase
= new StringPieceSortC(*collObj
, coll
, getRandomData8(status
));
1752 if (U_FAILURE(status
)) {
1759 UPerfFunction
* CollPerf2Test::TestUniStrBinSearch() {
1760 UErrorCode status
= U_ZERO_ERROR
;
1761 UPerfFunction
*testCase
= new UniStrBinSearch(*collObj
, coll
, getSortedData16(status
));
1762 if (U_FAILURE(status
)) {
1769 UPerfFunction
* CollPerf2Test::TestStringPieceBinSearchCpp() {
1770 UErrorCode status
= U_ZERO_ERROR
;
1771 UPerfFunction
*testCase
= new StringPieceBinSearchCpp(*collObj
, coll
, getSortedData8(status
));
1772 if (U_FAILURE(status
)) {
1779 UPerfFunction
* CollPerf2Test::TestStringPieceBinSearchC() {
1780 UErrorCode status
= U_ZERO_ERROR
;
1781 UPerfFunction
*testCase
= new StringPieceBinSearchC(*collObj
, coll
, getSortedData8(status
));
1782 if (U_FAILURE(status
)) {
1790 int main(int argc
, const char *argv
[])
1792 UErrorCode status
= U_ZERO_ERROR
;
1793 CollPerf2Test
test(argc
, argv
, status
);
1795 if (U_FAILURE(status
)){
1796 printf("The error is %s\n", u_errorName(status
));
1797 //TODO: print usage here
1801 if (test
.run() == FALSE
){
1802 fprintf(stderr
, "FAILED: Tests could not be run please check the arguments.\n");