1 /********************************************************************
3 * Copyright (C) 2008 IBM, Inc. All Rights Reserved.
5 ********************************************************************/
7 * This program tests string search performance.
12 #include "strsrchperf.h"
14 StringSearchPerformanceTest::StringSearchPerformanceTest(int32_t argc
, const char *argv
[], UErrorCode
&status
)
15 :UPerfTest(argc
,argv
,status
){
19 if(status
== U_ILLEGAL_ARGUMENT_ERROR
|| line_mode
){
20 fprintf(stderr
,gUsageString
, "strsrchperf");
24 src
= getBuffer(srcLen
, status
);
26 /* Get a word to find. Do this by selecting a random word with a word breakiterator. */
27 UBreakIterator
* brk
= ubrk_open(UBRK_WORD
, locale
, src
, srcLen
, &status
);
28 if(U_FAILURE(status
)){
29 fprintf(stderr
, "FAILED to create pattern for searching. Error: %s\n", u_errorName(status
));
32 start
= ubrk_preceding(brk
, 1000);
33 end
= ubrk_following(brk
, start
);
34 pttrnLen
= end
- start
;
35 UChar
* temp
= (UChar
*)malloc(sizeof(UChar
)*(pttrnLen
));
36 for (int i
= 0; i
< pttrnLen
; i
++) {
37 temp
[i
] = src
[start
++];
39 pttrn
= temp
; /* store word in pttrn */
42 /* Create the StringSearch object to be use in performance test. */
43 srch
= usearch_open(pttrn
, pttrnLen
, src
, srcLen
, locale
, NULL
, &status
);
44 if(U_FAILURE(status
)){
45 fprintf(stderr
, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status
));
51 StringSearchPerformanceTest::~StringSearchPerformanceTest() {
60 UPerfFunction
* StringSearchPerformanceTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
) {
62 TESTCASE(0,Test_ICU_Forward_Search
);
63 TESTCASE(1,Test_ICU_Backward_Search
);
72 UPerfFunction
* StringSearchPerformanceTest::Test_ICU_Forward_Search(){
73 StringSearchPerfFunction
* func
= new StringSearchPerfFunction(ICUForwardSearch
, srch
, src
, srcLen
, pttrn
, pttrnLen
);
77 UPerfFunction
* StringSearchPerformanceTest::Test_ICU_Backward_Search(){
78 StringSearchPerfFunction
* func
= new StringSearchPerfFunction(ICUBackwardSearch
, srch
, src
, srcLen
, pttrn
, pttrnLen
);
82 int main (int argc
, const char* argv
[]) {
83 UErrorCode status
= U_ZERO_ERROR
;
84 StringSearchPerformanceTest
test(argc
, argv
, status
);
85 if(U_FAILURE(status
)){
88 if(test
.run()==FALSE
){
89 fprintf(stderr
,"FAILED: Tests could not be run please check the arguments.\n");