/* ********************************************************************** * Copyright (c) 2002-2005, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** ********************************************************************** */ #ifndef _STRINGPERF_H #define _STRINGPERF_H #include #include "unicode/utypes.h" #include "unicode/unistr.h" #include "unicode/uperf.h" typedef std::wstring stlstring; /* Define all constants for test case operations */ #define MAXNUMLINES 40000 //Max number of lines in a test data file #define MAXSRCLEN 20 //Max length of one line. maybe a larger number, but it need more mem #define LOOPS 100 //Iterations //#define LOOPS 10 #define catenate_STRLEN 2 const UChar uTESTCHAR1 = 'a'; const wchar_t wTESTCHAR1 = 'a'; const UnicodeString uEMPTY; const stlstring sEMPTY; UnicodeString unistr; stlstring stlstr; // Simulate construction with a single-char string for basic_string wchar_t simulate[2]={wTESTCHAR1, 0}; /* Constants for scan operation */ U_STRING_DECL(scan_STRING, "Dot. 123. Some more data.", 25); const UnicodeString uScan_STRING=UnicodeString(scan_STRING); const stlstring sScan_STRING=stlstring(L"Dot. 123. Some more data."); /* global variables or constants for concatenation operation */ U_STRING_DECL(uCatenate_STR, "!!", 2); const stlstring sCatenate_STR=stlstring(L"!!"); static UnicodeString* catICU; static stlstring* catStd; UBool bCatenatePrealloc; /* type defines */ typedef struct WLine WLine; struct WLine { wchar_t name[100]; int32_t len; }; //struct to store one line of wchar_t string enum FnType { Fn_ICU, Fn_STD }; typedef FnType FnType; typedef void (*ICUStringPerfFn)(const UChar* src,int32_t srcLen, UnicodeString s0); typedef void (*StdStringPerfFn)(const wchar_t* src,int32_t srcLen, stlstring s0); class StringPerfFunction : public UPerfFunction { public: virtual long getEventsPerIteration(){ int loops = LOOPS; if (catICU) { delete catICU;} if (catStd) { delete catStd;} if (bCatenatePrealloc) { int to_alloc = loops * MAXNUMLINES * (MAXSRCLEN + catenate_STRLEN); catICU = new UnicodeString(to_alloc,'a',0); //catICU = new UnicodeString(); catStd = new stlstring(); //catStd -> reserve(loops * MAXNUMLINES * (MAXSRCLEN + catenate_STRLEN)); catStd -> reserve(110000000); } else { catICU = new UnicodeString(); catStd = new stlstring(); } return -1; } 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_)(wlines_[i].name,wlines_[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_)(wlines_[i].name,-1,sS0_[i]); } } } }else{ if(uselen_){ if (fnType_==Fn_ICU) { (*fn1_)(src_,srcLen_,*ubulk_); } else { (*fn2_)(wsrc_,wsrcLen_,*sbulk_); } }else{ if (fnType_==Fn_ICU) { (*fn1_)(src_,-1,*ubulk_); } else { (*fn2_)(wsrc_,-1,*sbulk_); } } } } virtual long getOperationsPerIteration() { if(line_mode_==TRUE){ return numLines_; }else{ return 1; } } StringPerfFunction(ICUStringPerfFn func, ULine* srcLines, int32_t srcNumLines, UBool uselen) { fn1_ = func; lines_=srcLines; wlines_=NULL; numLines_=srcNumLines; uselen_=uselen; line_mode_=TRUE; src_ = NULL; srcLen_ = 0; wsrc_ = NULL; wsrcLen_ = 0; fnType_ = Fn_ICU; uS0_=new UnicodeString[numLines_]; for(int32_t i=0; i