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