1 /********************************************************************
3 * Copyright (C) 2008-2012 IBM, Inc. All Rights Reserved.
5 ********************************************************************/
9 #include "unicode/usearch.h"
10 #include "unicode/uperf.h"
14 typedef void (*StrSrchFn
)(UStringSearch
* srch
, const UChar
* src
,int32_t srcLen
, const UChar
* pttrn
, int32_t pttrnLen
, UErrorCode
* status
);
16 class StringSearchPerfFunction
: public UPerfFunction
{
26 virtual void call(UErrorCode
* status
) {
27 (*fn
)(srch
, src
, srcLen
, pttrn
, pttrnLen
, status
);
30 virtual long getOperationsPerIteration() {
34 StringSearchPerfFunction(StrSrchFn func
, UStringSearch
* search
, const UChar
* source
,int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
) {
39 pttrnLen
= patternLen
;
44 class StringSearchPerformanceTest
: public UPerfTest
{
53 StringSearchPerformanceTest(int32_t argc
, const char *argv
[], UErrorCode
&status
);
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();
61 void ICUForwardSearch(UStringSearch
*srch
, const UChar
* source
, int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
, UErrorCode
* status
) {
64 match
= usearch_first(srch
, status
);
65 while (match
!= USEARCH_DONE
) {
66 match
= usearch_next(srch
, status
);
70 void ICUBackwardSearch(UStringSearch
*srch
, const UChar
* source
, int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
, UErrorCode
* status
) {
73 match
= usearch_last(srch
, status
);
74 while (match
!= USEARCH_DONE
) {
75 match
= usearch_previous(srch
, status
);
79 #endif /* _STRSRCHPERF_H */