| OLD | NEW |
| (Empty) |
| 1 /******************************************************************** | |
| 2 * COPYRIGHT: | |
| 3 * Copyright (C) 2008-2012 IBM, Inc. All Rights Reserved. | |
| 4 * | |
| 5 ********************************************************************/ | |
| 6 #ifndef _STRSRCHPERF_H | |
| 7 #define _STRSRCHPERF_H | |
| 8 | |
| 9 #include "unicode/usearch.h" | |
| 10 #include "unicode/uperf.h" | |
| 11 #include <stdlib.h> | |
| 12 #include <stdio.h> | |
| 13 | |
| 14 typedef void (*StrSrchFn)(UStringSearch* srch, const UChar* src,int32_t srcLen,
const UChar* pttrn, int32_t pttrnLen, UErrorCode* status); | |
| 15 | |
| 16 class StringSearchPerfFunction : public UPerfFunction { | |
| 17 private: | |
| 18 StrSrchFn fn; | |
| 19 const UChar* src; | |
| 20 int32_t srcLen; | |
| 21 const UChar* pttrn; | |
| 22 int32_t pttrnLen; | |
| 23 UStringSearch* srch; | |
| 24 | |
| 25 public: | |
| 26 virtual void call(UErrorCode* status) { | |
| 27 (*fn)(srch, src, srcLen, pttrn, pttrnLen, status); | |
| 28 } | |
| 29 | |
| 30 virtual long getOperationsPerIteration() { | |
| 31 return (long) srcLen; | |
| 32 } | |
| 33 | |
| 34 StringSearchPerfFunction(StrSrchFn func, UStringSearch* search, const UChar*
source,int32_t sourceLen, const UChar* pattern, int32_t patternLen) { | |
| 35 fn = func; | |
| 36 src = source; | |
| 37 srcLen = sourceLen; | |
| 38 pttrn = pattern; | |
| 39 pttrnLen = patternLen; | |
| 40 srch = search; | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 class StringSearchPerformanceTest : public UPerfTest { | |
| 45 private: | |
| 46 const UChar* src; | |
| 47 int32_t srcLen; | |
| 48 UChar* pttrn; | |
| 49 int32_t pttrnLen; | |
| 50 UStringSearch* srch; | |
| 51 | |
| 52 public: | |
| 53 StringSearchPerformanceTest(int32_t argc, const char *argv[], UErrorCode &st
atus); | |
| 54 ~StringSearchPerformanceTest(); | |
| 55 virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec, const char
*&name, char *par = NULL); | |
| 56 UPerfFunction* Test_ICU_Forward_Search(); | |
| 57 UPerfFunction* Test_ICU_Backward_Search(); | |
| 58 }; | |
| 59 | |
| 60 | |
| 61 void ICUForwardSearch(UStringSearch *srch, const UChar* source, int32_t sourceLe
n, const UChar* pattern, int32_t patternLen, UErrorCode* status) { | |
| 62 int32_t match; | |
| 63 | |
| 64 match = usearch_first(srch, status); | |
| 65 while (match != USEARCH_DONE) { | |
| 66 match = usearch_next(srch, status); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void ICUBackwardSearch(UStringSearch *srch, const UChar* source, int32_t sourceL
en, const UChar* pattern, int32_t patternLen, UErrorCode* status) { | |
| 71 int32_t match; | |
| 72 | |
| 73 match = usearch_last(srch, status); | |
| 74 while (match != USEARCH_DONE) { | |
| 75 match = usearch_previous(srch, status); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 #endif /* _STRSRCHPERF_H */ | |
| OLD | NEW |