
Also "If NewText <> """ might be redundant because CountString/FindString should pretty much return immediately on empty string?
wilbert,
ahhhh i think i see now, so after movzx youre able to do things like cmp eax instead of cmp al. i like!!!
Code: Select all
;DisableDebugger
Procedure.s RemoveMultiSpace(sText.s)
;#-----------------------------------
sText = LTrim(sText)
sTemp.s = ""
iCnt.i = 1
iSub.i = 1
iTotal.i = CountString(sText, Chr(32))
Dim sSub.s(iTotal)
Repeat
sTemp = Trim(StringField(sText, iCnt, Chr(32)))
If(Len(sTemp) > 0)
sSub(iSub) = sTemp
iSub = iSub + 1
EndIf
iCnt = iCnt + 1
Until iCnt = iTotal
sText = ""
iCnt = 1
Repeat
sText = sText + sSub(iCnt) + Chr(32)
iCnt = iCnt + 1
Until iCnt = iSub
ProcedureReturn(Trim(sText))
EndProcedure
iStartTime.i = ElapsedMilliseconds()
sTrimmed.s = RemoveMultiSpace(" Hello I am a splitted string Hello I am a splitted string Hello I am a splitted string ")
iElapsedTime.i = (ElapsedMilliseconds() - iStartTime)
;Debug sTrimmed
;Debug iElapsedTime
End
mm but it doesn't matter if you launch Secondary Thread and have Primary Thread doing nothing waiting for it, the timing will be the same, actually slightly worse by a few ms due to extra overhead, so just for the context of this exercise we probably dont need threadsIdeasVacuum wrote:In your main app, the procedure that replaces multi spaces could be run in a thread.
I havent thoroughly tested StringField on its own (but seeing as i had to stop the previous StringField test after 60 minutes in a test that took the other solutions ~30 secs i'd say yes perhaps it is really bad!), but another problem that compounds it is the string concatenation in the loop thats essentially required for StringField when used in that way. Because they're null-terminated strings, simply to append 1 byte requires scanning through the entire string buffer first, just like Len() would doIdeasVacuum wrote:Is StringField really so bad?
Code: Select all
sTest.s = Space(2000000)
Time1 = ElapsedMilliseconds()
For i = 1 To 10000
ilen.i = Len(sTest)
Next i
Time2 = ElapsedMilliseconds()
Debug(StrF((Time2-Time1)/10000,3) + " per Len() call")
Code: Select all
s1.s = "BEFORE"
sTest.s = ""
s3.s = "AFTER"
NewLen = Len(sTest)
Debug( FormatDate("%hh:%ii:%ss", Date()) + " @ 0x"+Hex(@sTest) + " Len=" + Str(NewLen) )
LastAddr = @sTest
LastSize = NewLen
For i = 1 To 2100000
If Mod(i,1000000) = 0
Debug( FormatDate("%hh:%ii:%ss", Date()) + " - " + Str(i) + "..." )
EndIf
sTest + "x" ;append 1 byte each loop
If LastAddr.i <> @sTest
NewLen = Len(sTest)
Debug( FormatDate("%hh:%ii:%ss", Date()) + " @ 0x"+Hex(@sTest) + " Len=" + Str(NewLen) + " SizeDiff=" + Str(NewLen-LastSize) )
LastAddr = @sTest: LastSize = NewLen
EndIf
Next i
The problem is, that it keeps starting at the beginning every time.Keya wrote:I havent thoroughly tested StringField on its own (but seeing as i had to stop the previous StringField test after 60 minutes in a test that took the other solutions ~30 secs i'd say yes perhaps it is really bad!)
That sounds like an enhancement request.......Most modern languages have a function to split a string into an array of strings
Code: Select all
;DisableDebugger
Procedure.s RemoveMultiSpace(sText.s)
;#-----------------------------------
Protected sText2.s = LTrim(sText), sTemp.s = ""
Protected iPosn.i = 1, iSub.i = 1, iCnt.i = 1, iSubInc.i = #False
Protected iTotal.i = Len(sText2)
Protected Dim sSub.s(iTotal)
Repeat
sTemp = Trim(Mid(sText2, iPosn, 1))
If(Len(sTemp) > 0)
sSub(iSub) = sSub(iSub) + sTemp
iSubInc = #True
Else
If(iSubInc = #True)
iSub = iSub + 1
iSubInc = #False
EndIf
EndIf
iPosn = iPosn + 1
Until iPosn = iTotal
sText = ""
Repeat
sText = sText + sSub(iCnt) + Chr(32)
iCnt = iCnt + 1
Until iCnt = iSub
ProcedureReturn(Trim(sText))
EndProcedure
sTrimmed.s = RemoveMultiSpace(" Hello I am a splitted string Hello I am a splitted string Hello I am a splitted string ")
Debug sTrimmed
End