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