1 /************************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
5 *************************************************************************
6 ********************************************************************
8 * Copyright (C) 2008-2012 IBM, Inc. All Rights Reserved.
10 ********************************************************************/
11 #ifndef _STRSRCHPERF_H
12 #define _STRSRCHPERF_H
14 #include "unicode/usearch.h"
15 #include "unicode/uperf.h"
19 typedef void (*StrSrchFn
)(UStringSearch
* srch
, const UChar
* src
,int32_t srcLen
, const UChar
* pttrn
, int32_t pttrnLen
, UErrorCode
* status
);
21 class StringSearchPerfFunction
: public UPerfFunction
{
31 virtual void call(UErrorCode
* status
) {
32 (*fn
)(srch
, src
, srcLen
, pttrn
, pttrnLen
, status
);
35 virtual long getOperationsPerIteration() {
39 StringSearchPerfFunction(StrSrchFn func
, UStringSearch
* search
, const UChar
* source
,int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
) {
44 pttrnLen
= patternLen
;
49 class StringSearchPerformanceTest
: public UPerfTest
{
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();
66 void ICUForwardSearch(UStringSearch
*srch
, const UChar
* source
, int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
, UErrorCode
* status
) {
69 match
= usearch_first(srch
, status
);
70 while (match
!= USEARCH_DONE
) {
71 match
= usearch_next(srch
, status
);
75 void ICUBackwardSearch(UStringSearch
*srch
, const UChar
* source
, int32_t sourceLen
, const UChar
* pattern
, int32_t patternLen
, UErrorCode
* status
) {
78 match
= usearch_last(srch
, status
);
79 while (match
!= USEARCH_DONE
) {
80 match
= usearch_previous(srch
, status
);
84 #endif /* _STRSRCHPERF_H */