/* ********************************************************************** * Copyright (c) 2002-2004, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** ********************************************************************** */ #ifndef _STRINGPERF_H #define _STRINGPERF_H #include #include "uperf.h" #include "unicode/utypes.h" #include "unicode/unistr.h" typedef std::basic_string stlstring; // Define all constants for test case operations #define MAXNUMLINES 40000 #define MAXSRCLEN 50 #define LOOPS 10 #define catenate_STRLEN 2 const UChar TESTCHAR1 = 'a'; const UChar* catenate_STR = L"!!"; const UnicodeString uEMPTY; const stlstring sEMPTY; const UnicodeString uScan_STRING=L"Dot. 123. Some more data."; const stlstring sScan_STRING=L"Dot. 123. Some more data."; // global variables for all operations UnicodeString unistr; stlstring stlstr; // for concatenation operation static UnicodeString* catICU; static stlstring* catStd; BOOL bCatenatePrealloc; // Simulate construction with a single-char string for basic_string UChar simulate[2]={TESTCHAR1, 0}; enum FnType { Fn_ICU, Fn_STD }; typedef FnType FnType; typedef void (*ICUStringPerfFn)(const UChar* src,int32_t srcLen, UnicodeString s0); typedef void (*StdStringPerfFn)(const UChar* src,int32_t srcLen, stlstring s0); class StringPerfFunction : public UPerfFunction { public: virtual void call(UErrorCode* status) { if(line_mode_==TRUE){ if(uselen_){ for(int32_t i = 0; i< numLines_; i++){ if (fnType_==Fn_ICU) { (*fn1_)(lines_[i].name,lines_[i].len,uS0_[i]); } else { (*fn2_)(lines_[i].name,lines_[i].len,sS0_[i]); } } }else{ for(int32_t i = 0; i< numLines_; i++){ if (fnType_==Fn_ICU) { (*fn1_)(lines_[i].name,-1,uS0_[i]); } else { (*fn2_)(lines_[i].name,-1,sS0_[i]); } } } }else{ if(uselen_){ if (fnType_==Fn_ICU) { (*fn1_)(src_,srcLen_,*ubulk_); } else { (*fn2_)(src_,srcLen_,*sbulk_); } }else{ if (fnType_==Fn_ICU) { (*fn1_)(src_,-1,*ubulk_); } else { (*fn2_)(src_,-1,*sbulk_); } } } } virtual long getOperationsPerIteration() { if(line_mode_==TRUE){ int32_t totalChars=0; for(int32_t i =0; i< numLines_; i++){ totalChars+= lines_[i].len; } return totalChars; }else{ return srcLen_; } } StringPerfFunction(ICUStringPerfFn func, ULine* srcLines, int32_t srcNumLines, UBool uselen) { fn1_ = func; lines_=srcLines; numLines_=srcNumLines; uselen_=uselen; line_mode_=TRUE; src_ = NULL; srcLen_ = 0; fnType_ = Fn_ICU; uS0_=new UnicodeString[numLines_]; for(int32_t i=0; i