2008-04-17 17:46:37 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
|
|
|
* Copyright (C) 2008 IBM, Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
#ifndef _STRSRCHPERF_H
|
|
|
|
#define _STRSRCHPERF_H
|
|
|
|
|
2008-04-18 19:14:38 +00:00
|
|
|
#include "unicode/ubrk.h"
|
|
|
|
#include "unicode/usearch.h"
|
2008-04-17 17:46:37 +00:00
|
|
|
#include "unicode/uperf.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-04-18 19:14:38 +00:00
|
|
|
typedef void (*StrSrchFn)(UStringSearch* srch, const UChar* src,int32_t srcLen, const UChar* pttrn, int32_t pttrnLen, UErrorCode* status);
|
|
|
|
|
2008-04-17 17:46:37 +00:00
|
|
|
class StringSearchPerfFunction : public UPerfFunction {
|
|
|
|
private:
|
2008-04-18 19:14:38 +00:00
|
|
|
StrSrchFn fn;
|
|
|
|
const UChar* src;
|
|
|
|
int32_t srcLen;
|
|
|
|
const UChar* pttrn;
|
|
|
|
int32_t pttrnLen;
|
|
|
|
UStringSearch* srch;
|
2008-04-17 17:46:37 +00:00
|
|
|
|
|
|
|
public:
|
2008-04-18 19:14:38 +00:00
|
|
|
virtual void call(UErrorCode* status) {
|
|
|
|
(*fn)(srch, src, srcLen, pttrn, pttrnLen, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual long getOperationsPerIteration() {
|
2008-04-18 21:07:32 +00:00
|
|
|
return (long)(srcLen/pttrnLen);
|
2008-04-18 19:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StringSearchPerfFunction(StrSrchFn func, UStringSearch* search, const UChar* source,int32_t sourceLen, const UChar* pattern, int32_t patternLen) {
|
|
|
|
fn = func;
|
|
|
|
src = source;
|
|
|
|
srcLen = sourceLen;
|
|
|
|
pttrn = pattern;
|
|
|
|
pttrnLen = patternLen;
|
|
|
|
srch = search;
|
|
|
|
}
|
2008-04-17 17:46:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class StringSearchPerformanceTest : public UPerfTest {
|
|
|
|
private:
|
2008-04-18 19:14:38 +00:00
|
|
|
const UChar* src;
|
|
|
|
int32_t srcLen;
|
|
|
|
UChar* pttrn;
|
|
|
|
int32_t pttrnLen;
|
|
|
|
UStringSearch* srch;
|
2008-04-17 17:46:37 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
StringSearchPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status);
|
|
|
|
~StringSearchPerformanceTest();
|
|
|
|
virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec, const char *&name, char *par = NULL);
|
2008-04-18 19:14:38 +00:00
|
|
|
|
|
|
|
UPerfFunction* Test_ICU_Forward_Search();
|
|
|
|
UPerfFunction* Test_ICU_Backward_Search();
|
2008-04-17 17:46:37 +00:00
|
|
|
};
|
|
|
|
|
2008-04-18 19:14:38 +00:00
|
|
|
void ICUForwardSearch(UStringSearch *srch, const UChar* source, int32_t sourceLen, const UChar* pattern, int32_t patternLen, UErrorCode* status) {
|
|
|
|
int32_t match;
|
|
|
|
|
|
|
|
match = usearch_first(srch, status);
|
|
|
|
while (match != USEARCH_DONE) {
|
|
|
|
match = usearch_next(srch, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ICUBackwardSearch(UStringSearch *srch, const UChar* source, int32_t sourceLen, const UChar* pattern, int32_t patternLen, UErrorCode* status) {
|
|
|
|
int32_t match;
|
|
|
|
|
|
|
|
match = usearch_last(srch, status);
|
|
|
|
while (match != USEARCH_DONE) {
|
|
|
|
match = usearch_previous(srch, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 17:46:37 +00:00
|
|
|
#endif /* _STRSRCHPERF_H */
|