X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..refs/heads/master:/icuSources/test/perf/collperf/collperf.cpp?ds=inline diff --git a/icuSources/test/perf/collperf/collperf.cpp b/icuSources/test/perf/collperf/collperf.cpp index 6dd508ba..137b31af 100644 --- a/icuSources/test/perf/collperf/collperf.cpp +++ b/icuSources/test/perf/collperf/collperf.cpp @@ -1,20 +1,29 @@ -/******************************************************************** +/*********************************************************************** +* © 2016 and later: Unicode, Inc. and others. +* License & terms of use: http://www.unicode.org/copyright.html#License +* +*********************************************************************** +*********************************************************************** * COPYRIGHT: -* Copyright (C) 2001-2006 IBM, Inc. All Rights Reserved. +* Copyright (C) 2001-2016 IBM, Inc. All Rights Reserved. * -********************************************************************/ +***********************************************************************/ #include #include #include #include #include +#include "cmemory.h" #include "unicode/uperf.h" #include "uoptions.h" #include "unicode/coll.h" #include - +#if !U_PLATFORM_HAS_WIN32_API +#define DWORD uint32_t +#define WCHAR wchar_t +#endif /* To store an array of string in continue space. Since string itself is treated as an array of UNIT, this @@ -109,6 +118,7 @@ public: ucol_getSortKey(col, data[i].icu_data, data[i].icu_data_len, icu_key, MAX_KEY_LENGTH); } +#if U_PLATFORM_HAS_WIN32_API // pre-generated in CollPerfTest::prepareData(), need not to check error here void win_key_null(int32_t i){ //LCMAP_SORTsk 0x00000400 // WC sort sk (normalize) @@ -118,6 +128,7 @@ public: void win_key_len(int32_t i){ LCMapStringW(win_langid, LCMAP_SORTKEY, data[i].win_data, data[i].win_data_len, win_key, MAX_KEY_LENGTH); } +#endif void posix_key_null(int32_t i){ strxfrm(posix_key, data[i].posix_data, MAX_KEY_LENGTH); @@ -189,69 +200,70 @@ public: ucol_closeElements(iter); } CmdIterAll(UErrorCode & status, UCollator * col, int32_t count, UChar * data, CALL call,int32_t,int32_t) - :count(count),data(data){ - exec_count = 0; - if (call == forward_null || call == backward_null) { - iter = ucol_openElements(col, data, -1, &status); - } else { - iter = ucol_openElements(col, data, count, &status); - } - - if (call == forward_null || call == forward_len){ - fn = icu_forward_all; - } else { - fn = icu_backward_all; - } + :count(count),data(data) + { + exec_count = 0; + if (call == forward_null || call == backward_null) { + iter = ucol_openElements(col, data, -1, &status); + } else { + iter = ucol_openElements(col, data, count, &status); } - virtual long getOperationsPerIteration(){return exec_count ? exec_count : 1;} - virtual void call(UErrorCode* status){ - (this->*fn)(status); + if (call == forward_null || call == forward_len){ + fn = &CmdIterAll::icu_forward_all; + } else { + fn = &CmdIterAll::icu_backward_all; } + } + virtual long getOperationsPerIteration(){return exec_count ? exec_count : 1;} - void icu_forward_all(UErrorCode* status){ - int strlen = count - 5; - int count5 = 5; - int strindex = 0; - ucol_setOffset(iter, strindex, status); - while (TRUE) { - if (ucol_next(iter, status) == UCOL_NULLORDER) { + virtual void call(UErrorCode* status){ + (this->*fn)(status); + } + + void icu_forward_all(UErrorCode* status){ + int strlen = count - 5; + int count5 = 5; + int strindex = 0; + ucol_setOffset(iter, strindex, status); + while (TRUE) { + if (ucol_next(iter, status) == UCOL_NULLORDER) { + break; + } + exec_count++; + count5 --; + if (count5 == 0) { + strindex += 10; + if (strindex > strlen) { break; } - exec_count++; - count5 --; - if (count5 == 0) { - strindex += 10; - if (strindex > strlen) { - break; - } - ucol_setOffset(iter, strindex, status); - count5 = 5; - } + ucol_setOffset(iter, strindex, status); + count5 = 5; } } + } - void icu_backward_all(UErrorCode* status){ - int strlen = count; - int count5 = 5; - int strindex = 5; - ucol_setOffset(iter, strindex, status); - while (TRUE) { - if (ucol_previous(iter, status) == UCOL_NULLORDER) { + void icu_backward_all(UErrorCode* status){ + int strlen = count; + int count5 = 5; + int strindex = 5; + ucol_setOffset(iter, strindex, status); + while (TRUE) { + if (ucol_previous(iter, status) == UCOL_NULLORDER) { + break; + } + exec_count++; + count5 --; + if (count5 == 0) { + strindex += 10; + if (strindex > strlen) { break; } - exec_count++; - count5 --; - if (count5 == 0) { - strindex += 10; - if (strindex > strlen) { - break; - } - ucol_setOffset(iter, strindex, status); - count5 = 5; - } + ucol_setOffset(iter, strindex, status); + count5 = 5; } } + } }; @@ -288,6 +300,7 @@ struct CmdQsort : public UPerfFunction{ return strcmp((char *) da->icu_key, (char *) db->icu_key); } +#if U_PLATFORM_HAS_WIN32_API static int win_cmp_null(const void *a, const void *b) { QCAST(); //CSTR_LESS_THAN 1 @@ -312,6 +325,7 @@ struct CmdQsort : public UPerfFunction{ return t - CSTR_EQUAL; } } +#endif #define QFUNC(name, func, data) \ static int name (const void *a, const void *b){ \ @@ -321,8 +335,10 @@ struct CmdQsort : public UPerfFunction{ QFUNC(posix_strcoll_null, strcoll, posix_data) QFUNC(posix_cmpkey, strcmp, posix_key) +#if U_PLATFORM_HAS_WIN32_API QFUNC(win_cmpkey, strcmp, win_key) QFUNC(win_wcscmp, wcscmp, win_data) +#endif QFUNC(icu_strcmp, u_strcmp, icu_data) QFUNC(icu_cmpcpo, u_strcmpCodePointOrder, icu_data) @@ -439,6 +455,7 @@ public: return strcmp( (char *) rnd[i].icu_key, (char *) ord[j].icu_key ); } +#if U_PLATFORM_HAS_WIN32_API int win_cmp_null(int32_t i, int32_t j) { int t = CompareStringW(win_langid, 0, rnd[i].win_data, -1, ord[j].win_data, -1); if (t == 0){ @@ -458,6 +475,7 @@ public: return t - CSTR_EQUAL; } } +#endif #define BFUNC(name, func, data) \ int name(int32_t i, int32_t j) { \ @@ -560,7 +578,7 @@ public: UOPTION_DEF("c_normal", 'n', UOPT_NO_ARG), // --normal UOPTION_DEF("c_strength", 's', UOPT_REQUIRES_ARG), // --strength <1-5> }; - int32_t opt_len = (sizeof(options)/sizeof(options[0])); + int32_t opt_len = UPRV_LENGTHOF(options); enum {i, r,f,a,c,l,n,s}; // The buffer between the option items' order and their references _remainingArgc = u_parseArgs(_remainingArgc, (char**)argv, opt_len, options); @@ -574,7 +592,7 @@ public: locale = "en_US"; // set default locale } - //#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API if (options[i].doesOccur) { char *endp; int tmp = strtol(options[i].value, &endp, 0); @@ -586,7 +604,7 @@ public: } else { win_langid = uloc_getLCID(locale); } - //#endif +#endif // Set up an ICU collator if (options[r].doesOccur) { @@ -670,15 +688,17 @@ public: int temp = 0; #define TEST_KEYGEN(testname, func)\ - TEST(testname, CmdKeyGen, col, win_langid, count, rnd_index, CmdKeyGen::func, 0) + TEST(testname, CmdKeyGen, col, win_langid, count, rnd_index, &CmdKeyGen::func, 0) TEST_KEYGEN(TestIcu_KeyGen_null, icu_key_null); TEST_KEYGEN(TestIcu_KeyGen_len, icu_key_len); TEST_KEYGEN(TestPosix_KeyGen_null, posix_key_null); +#if U_PLATFORM_HAS_WIN32_API TEST_KEYGEN(TestWin_KeyGen_null, win_key_null); TEST_KEYGEN(TestWin_KeyGen_len, win_key_len); +#endif #define TEST_ITER(testname, func)\ - TEST(testname, CmdIter, col, count, icu_data, CmdIter::func,0,0) + TEST(testname, CmdIter, col, count, icu_data, &CmdIter::func,0,0) TEST_ITER(TestIcu_ForwardIter_null, icu_forward_null); TEST_ITER(TestIcu_ForwardIter_len, icu_forward_len); TEST_ITER(TestIcu_BackwardIter_null, icu_backward_null); @@ -698,12 +718,14 @@ public: TEST_QSORT(TestIcu_qsort_usekey, icu_cmpkey); TEST_QSORT(TestPosix_qsort_strcoll_null, posix_strcoll_null); TEST_QSORT(TestPosix_qsort_usekey, posix_cmpkey); +#if U_PLATFORM_HAS_WIN32_API TEST_QSORT(TestWin_qsort_CompareStringW_null, win_cmp_null); TEST_QSORT(TestWin_qsort_CompareStringW_len, win_cmp_len); TEST_QSORT(TestWin_qsort_usekey, win_cmpkey); +#endif #define TEST_BIN(testname, func)\ - TEST(testname, CmdBinSearch, col, win_langid, count, rnd_index, ord_icu_key,CmdBinSearch::func) + TEST(testname, CmdBinSearch, col, win_langid, count, rnd_index, ord_icu_key, &CmdBinSearch::func) TEST_BIN(TestIcu_BinarySearch_strcoll_null, icu_strcoll_null); TEST_BIN(TestIcu_BinarySearch_strcoll_len, icu_strcoll_len); TEST_BIN(TestIcu_BinarySearch_usekey, icu_cmpkey); @@ -711,8 +733,10 @@ public: TEST_BIN(TestIcu_BinarySearch_cmpCPO, icu_cmpcpo); TEST_BIN(TestPosix_BinarySearch_strcoll_null, posix_strcoll_null); TEST_BIN(TestPosix_BinarySearch_usekey, posix_cmpkey); +#if U_PLATFORM_HAS_WIN32_API TEST_BIN(TestWin_BinarySearch_CompareStringW_null, win_cmp_null); TEST_BIN(TestWin_BinarySearch_CompareStringW_len, win_cmp_len); +#endif TEST_BIN(TestWin_BinarySearch_usekey, win_cmpkey); TEST_BIN(TestWin_BinarySearch_wcscmp, win_wcscmp); @@ -809,6 +833,7 @@ public: t = strxfrm(posix_key->last(), posix_data->dataOf(i), s); if (t != s) {status = U_INVALID_FORMAT_ERROR;return;} +#if U_PLATFORM_HAS_WIN32_API // Win data s = icu_data->lengthOf(i) + 1; // plus terminal NULL win_data->append_one(s); @@ -820,7 +845,7 @@ public: win_key->append_one(s); t = LCMapStringW(win_langid, LCMAP_SORTKEY, win_data->dataOf(i), win_data->lengthOf(i), (WCHAR *)(win_key->last()),s); if (t != s) {status = U_INVALID_FORMAT_ERROR;return;} - +#endif }; // append_one() will make points shifting, should not merge following code into previous iteration @@ -831,9 +856,11 @@ public: rnd_index[i].posix_key = posix_key->last(); rnd_index[i].posix_data = posix_data->dataOf(i); rnd_index[i].posix_data_len = posix_data->lengthOf(i); +#if U_PLATFORM_HAS_WIN32_API rnd_index[i].win_key = win_key->dataOf(i); rnd_index[i].win_data = win_data->dataOf(i); rnd_index[i].win_data_len = win_data->lengthOf(i); +#endif }; ucnv_close(conv); @@ -848,9 +875,11 @@ public: SORT(ord_icu_key, icu_cmpkey); SORT(ord_posix_data, posix_strcoll_null); SORT(ord_posix_key, posix_cmpkey); +#if U_PLATFORM_HAS_WIN32_API SORT(ord_win_data, win_cmp_len); SORT(ord_win_key, win_cmpkey); SORT(ord_win_wcscmp, win_wcscmp); +#endif SORT(ord_icu_strcmp, icu_strcmp); SORT(ord_icu_cmpcpo, icu_cmpcpo); }