]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/perf/strsrchperf/strsrchperf.h
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / test / perf / strsrchperf / strsrchperf.h
CommitLineData
46f4442e
A
1/********************************************************************
2 * COPYRIGHT:
51004dcb 3 * Copyright (C) 2008-2012 IBM, Inc. All Rights Reserved.
46f4442e
A
4 *
5 ********************************************************************/
6#ifndef _STRSRCHPERF_H
7#define _STRSRCHPERF_H
8
46f4442e
A
9#include "unicode/usearch.h"
10#include "unicode/uperf.h"
11#include <stdlib.h>
12#include <stdio.h>
13
14typedef void (*StrSrchFn)(UStringSearch* srch, const UChar* src,int32_t srcLen, const UChar* pttrn, int32_t pttrnLen, UErrorCode* status);
15
16class StringSearchPerfFunction : public UPerfFunction {
17private:
18 StrSrchFn fn;
19 const UChar* src;
20 int32_t srcLen;
21 const UChar* pttrn;
22 int32_t pttrnLen;
23 UStringSearch* srch;
24
25public:
26 virtual void call(UErrorCode* status) {
27 (*fn)(srch, src, srcLen, pttrn, pttrnLen, status);
28 }
29
30 virtual long getOperationsPerIteration() {
729e4ab9 31 return (long) srcLen;
46f4442e
A
32 }
33
34 StringSearchPerfFunction(StrSrchFn func, UStringSearch* search, const UChar* source,int32_t sourceLen, const UChar* pattern, int32_t patternLen) {
35 fn = func;
36 src = source;
37 srcLen = sourceLen;
38 pttrn = pattern;
39 pttrnLen = patternLen;
40 srch = search;
41 }
42};
43
44class StringSearchPerformanceTest : public UPerfTest {
45private:
46 const UChar* src;
47 int32_t srcLen;
48 UChar* pttrn;
49 int32_t pttrnLen;
50 UStringSearch* srch;
51
52public:
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);
46f4442e
A
56 UPerfFunction* Test_ICU_Forward_Search();
57 UPerfFunction* Test_ICU_Backward_Search();
58};
59
729e4ab9 60
46f4442e
A
61void ICUForwardSearch(UStringSearch *srch, const UChar* source, int32_t sourceLen, const UChar* pattern, int32_t patternLen, UErrorCode* status) {
62 int32_t match;
63
64 match = usearch_first(srch, status);
65 while (match != USEARCH_DONE) {
66 match = usearch_next(srch, status);
67 }
68}
69
70void ICUBackwardSearch(UStringSearch *srch, const UChar* source, int32_t sourceLen, const UChar* pattern, int32_t patternLen, UErrorCode* status) {
71 int32_t match;
72
73 match = usearch_last(srch, status);
74 while (match != USEARCH_DONE) {
75 match = usearch_previous(srch, status);
76 }
77}
78
79#endif /* _STRSRCHPERF_H */