X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/48b980fed3435926e0b3a8d72ecb58be703a1c7a..729e4ab9bc6618bc3d8a898e575df7f4019e29ca:/icuSources/test/perf/strsrchperf/strsrchperf.cpp diff --git a/icuSources/test/perf/strsrchperf/strsrchperf.cpp b/icuSources/test/perf/strsrchperf/strsrchperf.cpp index 4d899211..23d16d7d 100644 --- a/icuSources/test/perf/strsrchperf/strsrchperf.cpp +++ b/icuSources/test/perf/strsrchperf/strsrchperf.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (C) 2008 IBM, Inc. All Rights Reserved. + * Copyright (C) 2008-2009 IBM, Inc. All Rights Reserved. * ********************************************************************/ /** @@ -14,7 +14,13 @@ StringSearchPerformanceTest::StringSearchPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status) :UPerfTest(argc,argv,status){ int32_t start, end; + +#ifdef TEST_BOYER_MOORE_SEARCH + bms = NULL; +#else srch = NULL; +#endif + pttrn = NULL; if(status== U_ILLEGAL_ARGUMENT_ERROR || line_mode){ fprintf(stderr,gUsageString, "strsrchperf"); @@ -22,7 +28,8 @@ StringSearchPerformanceTest::StringSearchPerformanceTest(int32_t argc, const cha } /* Get the Text */ src = getBuffer(srcLen, status); - + +#if 0 /* Get a word to find. Do this by selecting a random word with a word breakiterator. */ UBreakIterator* brk = ubrk_open(UBRK_WORD, locale, src, srcLen, &status); if(U_FAILURE(status)){ @@ -38,9 +45,38 @@ StringSearchPerformanceTest::StringSearchPerformanceTest(int32_t argc, const cha } pttrn = temp; /* store word in pttrn */ ubrk_close(brk); +#else + /* The first line of the file contains the pattern */ + start = 0; + + for(end = start; ; end += 1) { + UChar ch = src[end]; + + if (ch == 0x000A || ch == 0x000D || ch == 0x2028) { + break; + } + } + + pttrnLen = end - start; + UChar* temp = (UChar*)malloc(sizeof(UChar)*(pttrnLen)); + for (int i = 0; i < pttrnLen; i++) { + temp[i] = src[start++]; + } + pttrn = temp; /* store word in pttrn */ +#endif +#ifdef TEST_BOYER_MOORE_SEARCH + UnicodeString patternString(pttrn, pttrnLen); + UCollator *coll = ucol_open(locale, &status); + CollData *data = CollData::open(coll, status); + + targetString = new UnicodeString(src, srcLen); + bms = new BoyerMooreSearch(data, patternString, targetString, status); +#else /* Create the StringSearch object to be use in performance test. */ srch = usearch_open(pttrn, pttrnLen, src, srcLen, locale, NULL, &status); +#endif + if(U_FAILURE(status)){ fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status)); return; @@ -49,12 +85,23 @@ StringSearchPerformanceTest::StringSearchPerformanceTest(int32_t argc, const cha } StringSearchPerformanceTest::~StringSearchPerformanceTest() { + CollData *data = bms->getData(); + UCollator *coll = data->getCollator(); + + delete bms; + delete targetString; + CollData::close(data); + ucol_close(coll); + if (pttrn != NULL) { free(pttrn); } + +#ifndef TEST_BOYER_MOORE_SEARCH if (srch != NULL) { usearch_close(srch); } +#endif } UPerfFunction* StringSearchPerformanceTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char *par) { @@ -70,12 +117,20 @@ UPerfFunction* StringSearchPerformanceTest::runIndexedTest(int32_t index, UBool } UPerfFunction* StringSearchPerformanceTest::Test_ICU_Forward_Search(){ +#ifdef TEST_BOYER_MOORE_SEARCH + StringSearchPerfFunction *func = new StringSearchPerfFunction(ICUForwardSearch, bms, src, srcLen, pttrn, pttrnLen); +#else StringSearchPerfFunction* func = new StringSearchPerfFunction(ICUForwardSearch, srch, src, srcLen, pttrn, pttrnLen); +#endif return func; } UPerfFunction* StringSearchPerformanceTest::Test_ICU_Backward_Search(){ +#ifdef TEST_BOYER_MOORE_SEARCH + StringSearchPerfFunction *func = new StringSearchPerfFunction(ICUBackwardSearch, bms, src, srcLen, pttrn, pttrnLen); +#else StringSearchPerfFunction* func = new StringSearchPerfFunction(ICUBackwardSearch, srch, src, srcLen, pttrn, pttrnLen); +#endif return func; }