;========================================================================================================================================== ; Extracting the leftmost number string of given length from a line of text and numbers. ; ; Profiling Performance Test. ; ;------------------------------------------------------------------------------------------------------------------------------------------ ; (c)Detlev Dalitz.20080823.20100228. ;========================================================================================================================================== strTestLine = "54321 of 123456789 people on date20080831 run 12 times faster." intStrLen = 5 ; Search for number string "54321". ;intStrLen = 9 ; Search for number string "123456789". ;intStrLen = 8 ; Search for number string "20080831". ;intStrLen = 2 ; Search for number string "12". intLoops = 2000 intTicks1 = 0 intTicks2 = 0 Exclusive (@ON) For intLoop = 1 To intLoops ;---; ; 1 ; ;---+-------------------------------------------------------------------------------------------------------------------------------------- ; Test. ;------------------------------------------------------------------------------------------------------------------------------------------ intStart = GetTickCount () strLine = strTestLine strLine = StrClean (strLine, "0123456789", " ", @TRUE, 2) ; Replace alpha characters with space character. While StrIndex (strLine, " ", 1, @FWDSCAN) ; Shrink space character sequences to one space. strLine = StrReplace (strLine, " ", " ") EndWhile intC = ItemCount (strLine, " ") For intI = 1 To intC strItem = ItemExtract (intI, strLine, " ") If StrLen (strItem) == intStrLen Then Break ; If length matches, then number found. Next intTicks1 = GetTickCount () - intStart + intTicks1 ;---; ; 2 ; ;---+-------------------------------------------------------------------------------------------------------------------------------------- ; Test. ;------------------------------------------------------------------------------------------------------------------------------------------ intStart = GetTickCount () strLine = strTestLine strLine = StrClean (strLine, "0123456789", " ", @TRUE, 2) ; Replace all alpha characters with space character. intC = ItemCount (strLine, " ") For intI = 1 To intC strItem = ItemExtract (intI, strLine, " ") If StrLen (strItem) == intStrLen Then Break ; If length matches, then number found. Next intTicks2 = GetTickCount () - intStart + intTicks2 Next Exclusive (@OFF) ;------------------------------------------------------------------------------------------------------------------------------------------ ; Result. ;------------------------------------------------------------------------------------------------------------------------------------------ intTicks = intTicks1 + intTicks2 If intTicks < 1 Then intTicks = 1 intPct1 = 100.0 * intTicks1 / intTicks intPct2 = 100.0 * intTicks2 / intTicks Decimals (1) strMsgTitle = "Performance Test Result" strMsgText = "Method" : @TAB : "Ticks" : @TAB : "Percent" : @LF strMsgText = strMsgText : "1:" : @TAB : intTicks1 : @TAB : intPct1 : @LF strMsgText = strMsgText : "2:" : @TAB : intTicks2 : @TAB : intPct2 : @LF ClipPut (strMsgTitle : @CRLF : StrReplace (strMsgText, @LF, @CRLF)) Message (strMsgTitle, strMsgText) :CANCEL Exit ;------------------------------------------------------------------------------------------------------------------------------------------ ; strTestLine = "54321 of 123456789 people on date20080831 run 12 times faster." ;------------------------------------------------------------------------------------------------------------------------------------------ ; intStrLen = 2 ; Search for number string "12". ; Performance Test Result ; Method Ticks Percent ; 1: 5043 24.7 ; 2: 15346 75.3 ;------------------------------------------------------------------------------------------------------------------------------------------ ; intStrLen = 8 ; Search for number string "20080831". ; Performance Test Result ; Method Ticks Percent ; 1: 4946 30.9 ; 2: 11085 69.1 ;------------------------------------------------------------------------------------------------------------------------------------------ ; intStrLen = 9 ; Search for number string "123456789". ; Performance Test Result ; Method Ticks Percent ; 1: 4205 52.8 ; 2: 3766 47.2 ;------------------------------------------------------------------------------------------------------------------------------------------ ; intStrLen = 5 ; Search for number string "54321". ; Performance Test Result ; Method Ticks Percent ; 1: 3403 68.9 ; 2: 1534 31.1 ;------------------------------------------------------------------------------------------------------------------------------------------ ;==========================================================================================================================================