1 /********************************************************************
3 * Copyright (C) 2008 IBM, Inc. All Rights Reserved.
5 ********************************************************************/
9 #include "unicode/ubrk.h"
10 #include "unicode/usearch.h"
11 #include "unicode/uperf.h"
15 typedef void (*StrSrchFn
)(UStringSearch
* srch
, const UChar
* src
,int32_t srcLen
, const UChar
* pttrn
, int32_t pttrnLen
, UErrorCode
* status
);
17 class StringSearchPerfFunction
: public UPerfFunction
{
27 virtual void call(UErrorCode
* status
) {
28 (*fn
)(srch
, src
, srcLen
, pttrn
, pttrnLen
, status
);
31 virtual long getOperationsPerIteration() {
32 return (long)(srcLen
/pttrnLen
);
35 StringSearchPerfFunction(StrSrchFn func
, UStringSearch
* search
, const UChar
* source
,int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
) {
40 pttrnLen
= patternLen
;
45 class StringSearchPerformanceTest
: public UPerfTest
{
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
);
58 UPerfFunction
* Test_ICU_Forward_Search();
59 UPerfFunction
* Test_ICU_Backward_Search();
62 void ICUForwardSearch(UStringSearch
*srch
, const UChar
* source
, int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
, UErrorCode
* status
) {
65 match
= usearch_first(srch
, status
);
66 while (match
!= USEARCH_DONE
) {
67 match
= usearch_next(srch
, status
);
71 void ICUBackwardSearch(UStringSearch
*srch
, const UChar
* source
, int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
, UErrorCode
* status
) {
74 match
= usearch_last(srch
, status
);
75 while (match
!= USEARCH_DONE
) {
76 match
= usearch_previous(srch
, status
);
80 #endif /* _STRSRCHPERF_H */