;==========================================================================================================================================;; Profiling Performance Contest.;; - 20111216.HowTo.XML.MassReplace.1.wbt (StrIndexWild); - 20111218.HowTo.XML.MassReplace.2.wbt (Binary Buffer); - 20111219.HowTo.XML.MassReplace.3.wbt (DOM Extender); - 20111220.HowTo.XML.MassReplace.4.wbt (Microsoft XML DOM); - 20111220.HowTo.XML.MassReplace.5.wbt (Regular Expression); - 20111220.HowTo.XML.MassReplace.6.wbt (FileRead); - 20111223.HowTo.XML.MassReplace.7.wbt (Microsoft XML DOM XSLT);;------------------------------------------------------------------------------------------------------------------------------------------; (c)Detlev Dalitz.20111223.;==========================================================================================================================================DirChange(DirScript()); How many different test cases?intContestCaseMax=2; How many loops to run?intContestLoopMax=1; What group of contestants to examine?intContestantMin=1intContestantMax=7; Display preview of test case results?;blnDisplayPreview = @TRUEblnDisplayPreview=@FALSE; Display contest status in windows title?blnDisplayStatus=@TRUE;blnDisplayStatus = @FALSEGoSubDEFINE_CONTEST_FUNCTIONS;==========================================================================================================================================GoSubDEFINE_FUNCTIONS; Run the contest once and display the results for verifying.; Then press CANCEL to abort or OK to run complete contest.IfblnDisplayPreviewForintContestCase=1TointContestCaseMaxudsPrepareTestCase(intContestCase)udsPrepareCounters()ForintContestant=intContestantMinTointContestantMaxudsRunContestant(intContestant)NextIf@CANCEL==udfArrayDumpToItemList(arrContestResults,intContestantMin,intContestantMax,@LF)ThenGotoCANCELNextEndIf; Run complete contest.WinShow("")strContestResult=""SwitchblnDisplayStatusCase@TRUEForintContestCase=1TointContestCaseMaxudsPrepareTestCase(intContestCase)udsPrepareCounters()ForintContestLoop=1TointContestLoopMaxForintContestant=intContestantMinTointContestantMaxWinTitle("","Profiling|Case=":intContestCaseMax:".":intContestCase:"|Contestant=":intContestantMax:".":intContestant:"|Loop=":intContestLoopMax:".":intContestLoop)udsRunContestant(intContestant)NextNextstrContestResult=strContestResult:@LF:udsResultPerTestCase()NextBreakCase@FALSEForintContestCase=1TointContestCaseMaxudsPrepareTestCase(intContestCase)udsPrepareCounters()ForintContestLoop=1TointContestLoopMaxForintContestant=intContestantMinTointContestantMaxudsRunContestant(intContestant)NextNextstrContestResult=strContestResult:@LF:udsResultPerTestCase()NextBreakEndSwitchstrContestResult=strContestResult:@LF:strPre:StrFill("-",intLenSum)strContestResult=StrSub(strContestResult,2,-1)Message(strMsgTitle,strContestResult)ClipPut(StrReplace(strContestResult,@LF,@CRLF)):CANCELExit;==========================================================================================================================================;==========================================================================================================================================:DEFINE_CONTEST_FUNCTIONS;==========================================================================================================================================;------------------------------------------------------------------------------------------------------------------------------------------#DefineSubRoutineudsPrepareTestCase(intContestCase)strCallFile1="20111216.HowTo.XML.MassReplace.1.wbt"strCallFile2="20111218.HowTo.XML.MassReplace.2.wbt"strCallFile3="20111219.HowTo.XML.MassReplace.3.wbt"strCallFile4="20111220.HowTo.XML.MassReplace.4.wbt"strCallFile5="20111220.HowTo.XML.MassReplace.5.wbt"strCallFile6="20111220.HowTo.XML.MassReplace.6.wbt"strCallFile7="20111223.HowTo.XML.MassReplace.7.wbt"strContestant1=strCallFile1:" (StrIndexWild)"strContestant2=strCallFile2:" (Binary Buffer)"strContestant3=strCallFile3:" (DOM Extender)"strContestant4=strCallFile4:" (Microsoft XML DOM)"strContestant5=strCallFile5:" (Regular Expression)"strContestant6=strCallFile6:" (FileRead)"strContestant7=strCallFile7:" (Microsoft XML DOM XSLT)"SwitchintContestCaseCase1blnresult=FileCopy("Config.1.ini","Config.ini",@FALSE)Display(3,"Config.ini",FileGet("Config.ini"))BreakCase2blnresult=FileCopy("Config.2.ini","Config.ini",@FALSE)Display(3,"Config.ini",FileGet("Config.ini"))BreakEndSwitch#EndSubRoutine;------------------------------------------------------------------------------------------------------------------------------------------;------------------------------------------------------------------------------------------------------------------------------------------#DefineSubRoutineudsRunContestant(intContestant)Exclusive(@ON)SwitchintContestantCase1arrContestants[intContestant]=strContestant1intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile1,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakCase2arrContestants[intContestant]=strContestant2intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile2,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakCase3arrContestants[intContestant]=strContestant3intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile3,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakCase4arrContestants[intContestant]=strContestant4intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile4,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakCase5arrContestants[intContestant]=strContestant5intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile5,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakCase6arrContestants[intContestant]=strContestant6intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile6,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakCase7arrContestants[intContestant]=strContestant7intStart=GetTickCount()arrResult%intContestant%=Call(strCallFile7,"")intStop=GetTickCount()arrContestTicks[intContestant]=arrContestTicks[intContestant]+intStop-intStartarrContestResults[intContestant]=udfArrayJoin(arrResult%intContestant%,"")intLen%intContestant%=StrLen(arrContestResults[intContestant])BreakEndSwitchExclusive(@OFF)#EndSubRoutine;------------------------------------------------------------------------------------------------------------------------------------------;------------------------------------------------------------------------------------------------------------------------------------------#DefineFunctionudfArrayJoin(arrArray,strDelimiter)objJSC=CreateObject("MSScriptControl.ScriptControl")objJSC.Language="JScript"objJSC.AllowUI=@FALSESwitch@TRUECase256==VarType(arrArray); WinBatch Array.CaseObjectTypeGet(arrArray)=="ARRAY|VARIANT"; Variant ArrayobjJSC.AddCode(:"function VB2JSArray(objVBArray){var a;try{a=new VBArray(objVBArray).toArray();}catch(e){a=new Array(objVBArray);}return a;}")objJSC.AddCode(:"function ArrayJoin(objVBArray,strDelimiter){return VB2JSArray(objVBArray).join(strDelimiter);}")strJoined=objJSC.Run(:"ArrayJoin",arrArray,strDelimiter)BreakCase@TRUEstrJoined=""EndSwitchReturnstrJoined;..........................................................................................................................................; This UDF "udfArrayJoin" joins all elements of an array into a string.; The elements will be separated by the specified delimiter string.;; Parameter:; arrArray ....... A one-dimensional array of strings. Array type can be WinBatch Array or Variant Array.; strDelimiter ... A single character or a string. The elements will be separated by this delimiter.;..........................................................................................................................................; (c)Detlev Dalitz.20100121.; Jim Dippner.20080221: changed VB2JSArray.; David Wang.20060704: created VB2JSArray.;..........................................................................................................................................#EndFunction;------------------------------------------------------------------------------------------------------------------------------------------;==========================================================================================================================================Return; from GoSub DEFINE_CONTEST_FUNCTIONS;==========================================================================================================================================;==========================================================================================================================================:DEFINE_FUNCTIONS;==========================================================================================================================================;------------------------------------------------------------------------------------------------------------------------------------------#DefineFunctionudfArrayDumpToItemList(arrArray,intFirst,intLast,strDelimiter)If!ArrInfo(arrArray,-1)ThenReturn"*ARRAY_IS_INVALID*"; No Array, return invalid itemlist, i. e. empty string "".IfArrInfo(arrArray,0)!=1ThenReturn"*ARRAY_IS_NOT_DIM_1*"; Array is not a dim-1 array, return invalid itemlist, i. e. empty string "".intElements=ArrInfo(arrArray,1)IfintElements==0ThenReturn"*ARRAY_HAS_NO_ELEMENTS*"; Array has no element.intFirst=Min(Max(intFirst,0),intElements-1)intLast=Min(Max(intLast,0),intElements-1)strItemList=""intFixSize=StrLen(intLast)ForintI=intFirstTointLastIf!!VarType(arrArray[intI])IfarrArray[intI]==""strItemList=ItemInsert(StrFixLeft(intI,"0",intFixSize):"|":"*ARRAY_ELEMENT_IS_EMPTY_STRING*",-1,strItemList,strDelimiter)ElsearrArray[intI]=StrReplace(StrReplace(StrReplace(StrReplace(arrArray[intI],@CRLF,"@CRLF"),@CR,"@CR"),@LF,"@LF"),@TAB,"@TAB"); Make WB style.arrArray[intI]=StrSub(arrArray[intI],1,200); Special truncation just for the small buffer of AskItemList.strItemList=ItemInsert(StrFixLeft(intI,"0",intFixSize):"|":arrArray[intI],-1,strItemList,strDelimiter)EndIfElsestrItemList=ItemInsert(StrFixLeft(intI,"0",intFixSize):"|":"*ARRAY_ELEMENT_IS_UNDEFINED*",-1,strItemList,strDelimiter)EndIfNextIntControl(28,1,0,0,0)IntControl(63,050,200,950,800)ReturnAskItemlist("Profiling|Preview Contestant Result",strItemList,strDelimiter,@UNSORTED,@SINGLE); This returns a Unicode string of VarType=128.:CANCELReturn@CANCEL;..........................................................................................................................................; This UDF "udfArrayDumpToItemList" reads a dim-1 array and returns an itemlist of all array cell items within an AskItemList dialog..;; Return values:; "*ARRAY_IS_INVALID*" ... Invalid array resp. this is no array.; "*ARRAY_IS_NOT_DIM_1*" ... Array is not a dim-1 array.; "*ARRAY_HAS_NO_ELEMENTS*" ... Array has no element.; "*ARRAY_ELEMENT_IS_EMPTY_STRING*" ... Array element has vartype STRING but is empty.; "*ARRAY_ELEMENT_IS UNDEFINED*" ... Array element has undefined VarType.; value ... Current value of the array element.;; Example: strItemList = udfArrayDumpToItemList (arrArray, 0, 19, @TAB);; Detlev Dalitz.20090515.20100122.20101222.;..........................................................................................................................................#EndFunction;------------------------------------------------------------------------------------------------------------------------------------------;------------------------------------------------------------------------------------------------------------------------------------------#DefineSubRoutineudsPrepareCounters()arrContestants=ArrDimension(1+intContestantMax); Array index 0 not used.arrContestResults=ArrDimension(1+intContestantMax); Array index 0 not used.arrContestTicks=ArrDimension(1+intContestantMax); Array index 0 used for the sum.arrContestPct=ArrDimension(1+intContestantMax); Array index 0 not used.ArrInitialize(arrContestants,"")ArrInitialize(arrContestResults,"")ArrInitialize(arrContestTicks,0)ArrInitialize(arrContestPct,0.0)#EndSubRoutine;------------------------------------------------------------------------------------------------------------------------------------------;------------------------------------------------------------------------------------------------------------------------------------------#DefineSubRoutineudsResultPerTestCase()Decimals(1)ForintContestant=intContestantMinTointContestantMaxarrContestTicks[0]=arrContestTicks[0]+arrContestTicks[intContestant]NextintContestTicksMin=arrContestTicks[0]ForintContestant=intContestantMinTointContestantMaxintContestTicksMin=Min(intContestTicksMin,arrContestTicks[intContestant])NextIfarrContestTicks[0]<1ThenarrContestTicks[0]=1; To prevent dividing by zero.ForintContestant=intContestantMinTointContestantMaxarrContestPct[intContestant]=100.0*arrContestTicks[intContestant]/arrContestTicks[0]Next; Format output.strMsgTitle="Performance Contest Result"strTest="Test"strTicks="Ticks"strPct="Pct"strContestant="Contestant"strCase="Contest Case = "strIter="Iterations = "strSep=""strPre="; "strWinner="<== The Winner"strDT="DateTime = "intLenTest=Max(StrLen(strTest),StrLen(intContestantMax))intLenTicks=StrLen(strTicks)intLenPct=StrLen(strPct)intLenContestant=StrLen(strContestant)intLenSep=StrLen(strSep)intLenWinner=StrLen(strWinner)ForintContestant=intContestantMinTointContestantMaxintLenTicks=Max(intLenTicks,StrLen(arrContestTicks[intContestant]))intLenPct=Max(intLenPct,StrLen(arrContestPct[intContestant]))intLenContestant=Max(intLenContestant,StrLen(arrContestants[intContestant]))NextintLenSum=intLenTest+intLenTicks+intLenPct+intLenContestant+intLenWinner+4*intLenSepstrTest=StrFixLeft(strTest,"",intLenTest)strTicks=StrFixLeft(strTicks,"",intLenTicks)strPct=StrFixLeft(strPct,"",intLenPct)strResult=strPre:StrFill("-",intLenSum):@LF:strPre:strMsgTitlestrResult=strResult:@LF:strPre:strCase:intContestCasestrResult=strResult:@LF:strPre:strIter:intContestLoopMaxstrResult=strResult:@LF:strPre:strTest:strSep:strTicks:strSep:strPct:strSep:strContestantForintContestant=intContestantMinTointContestantMaxstrTest=StrFixLeft(intContestant,"",intLenTest)strTicks=StrFixLeft(arrContestTicks[intContestant],"",intLenTicks)strPct=StrFixLeft(arrContestPct[intContestant],"",intLenPct)strContestant=StrFix(arrContestants[intContestant],"",intLenContestant)IfarrContestTicks[intContestant]==intContestTicksMinThenstrContestant=strContestant:strSep:strWinnerstrResult=strResult:@LF:strPre:strTest:strSep:strTicks:strSep:strPct:strSep:strContestantNextReturnstrResult:@LF:strPre:strDT:TimeYmdHms()#EndSubRoutine;------------------------------------------------------------------------------------------------------------------------------------------;==========================================================================================================================================Return; from GoSub DEFINE_FUNCTIONS;==========================================================================================================================================; -------------------------------------------------------------------------------------------------; Performance Contest Result; Contest Case = 1; Iterations = 100; Test Ticks Pct Contestant; 1 76150 6.3 20111216.HowTo.XML.MassReplace.1.wbt (StrIndexWild); 2 54671 4.5 20111218.HowTo.XML.MassReplace.2.wbt (Binary Buffer); 3 55285 4.5 20111219.HowTo.XML.MassReplace.3.wbt (DOM Extender); 4 14590 1.2 20111220.HowTo.XML.MassReplace.4.wbt (Microsoft XML DOM); 5 9248 0.8 20111220.HowTo.XML.MassReplace.5.wbt (Regular Expression) <== The Winner; 6 993066 81.6 20111220.HowTo.XML.MassReplace.6.wbt (FileRead); 7 14703 1.2 20111220.HowTo.XML.MassReplace.7.wbt (Microsoft XML DOM XSLT); DateTime = 2011:12:23:21:48:38; -------------------------------------------------------------------------------------------------; Performance Contest Result; Contest Case = 2; Iterations = 100; Test Ticks Pct Contestant; 1 476009 26.7 20111216.HowTo.XML.MassReplace.1.wbt (StrIndexWild); 2 217914 12.2 20111218.HowTo.XML.MassReplace.2.wbt (Binary Buffer); 3 77191 4.3 20111219.HowTo.XML.MassReplace.3.wbt (DOM Extender); 4 17574 1.0 20111220.HowTo.XML.MassReplace.4.wbt (Microsoft XML DOM); 5 19645 1.1 20111220.HowTo.XML.MassReplace.5.wbt (Regular Expression); 6 963121 53.9 20111220.HowTo.XML.MassReplace.6.wbt (FileRead); 7 14241 0.8 20111220.HowTo.XML.MassReplace.7.wbt (Microsoft XML DOM XSLT) <== The Winner; DateTime = 2011:12:23:22:18:35; -------------------------------------------------------------------------------------------------