my tests are: AHK U32 v1.1.24.05, high priority, Windows 7 x64
speed tests for generating repeated string:
'VarSetCapacity fill bytes, replace' beats 'loop append'
(repeated strings themselves are often useful for speed tests)
speed tests for parsing CRLF-delimited lines:
'parse LF ignore CR' just beats 'replace CRLF with LF, parse LF'
(out of interest 'replace CR with LF, parse LF, ignore blank lines',
also included, was essentially twice the loops, twice the time)
speed tests for InStr case sensitive/case insensitive:
case insensitive beats case sensitive
(although I might have thought case sensitive had less to check
e.g. check 'b' versus check 'B' and 'b', so would be faster)
Code: Select all
;speed tests for generating repeated string
;'VarSetCapacity fill bytes, replace' beats 'loop append'
q::
vNum := 100000000 ;10^8
;test 1 - loop append
vTickCount1 := A_TickCount
vText := ""
VarSetCapacity(vText, vNum*2)
Loop, % vNum/10
vText .= "abcdefgh`r`n"
vTickCount2 := A_TickCount
MsgBox % vTime1 := vTickCount2-vTickCount1
vText2 := vText
;test 2 - VarSetCapacity fill bytes, replace
vTickCount1 := A_TickCount
vText := ""
VarSetCapacity(vText, (vNum/10)*2, 1)
vText := StrReplace(vText, Chr(257), "abcdefgh`r`n")
vTickCount2 := A_TickCount
MsgBox % vTime2 := vTickCount2-vTickCount1
;MsgBox % (vText = vText2)
MsgBox % Clipboard := vTime1 " " vTime2 ;e.g. 1107 390, 1217 375
Return
;==================================================
;speed tests for parsing CRLF-delimited lines
;'parse LF ignore CR' just beats 'replace CRLF with LF, parse LF'
w::
vNum := 100000000 ;10^8
vText := ""
VarSetCapacity(vText, (vNum/10)*2, 1)
vText := StrReplace(vText, Chr(257), "abcdefgh`r`n")
vTextOrig := vText
;test 1 - replace CRLF with LF, parse LF
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
vTickCount1 := A_TickCount
vText := StrReplace(vText, "`r`n", "`n")
Loop, Parse, vText, `n
vOutput .= A_LoopField "`r`n"
vTickCount2 := A_TickCount
MsgBox % vTime1 := vTickCount2-vTickCount1
;MsgBox % (vTextOrig "`r`n" = vOutput)
;test 2 - parse LF ignore CR
vText := vTextOrig
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
vTickCount1 := A_TickCount
Loop, Parse, vText, `n, `r
vOutput .= A_LoopField "`r`n"
vTickCount2 := A_TickCount
MsgBox % vTime2 := vTickCount2-vTickCount1
;MsgBox % (vTextOrig "`r`n" = vOutput)
;test 3 - replace CR with LF, parse LF, ignore blank lines
vText := vTextOrig
vOutput := ""
VarSetCapacity(vOutput, StrLen(vText)*2)
vTickCount1 := A_TickCount
vText := StrReplace(vText, "`r", "`n")
Loop, Parse, vText, `n
if !(A_LoopField = "")
vOutput .= A_LoopField "`r`n"
vTickCount2 := A_TickCount
MsgBox % vTime3 := vTickCount2-vTickCount1
;MsgBox % (vTextOrig = vOutput)
MsgBox % Clipboard := vTime1 " " vTime2 " " vTime3 ;e.g. 3026 2714, 3042 2714, 3057 2730 6147, 3198 2683 6100, 3089 2699 6209
Return
;==================================================
;speed tests for InStr case sensitive/case insensitive
;case insensitive beats case sensitive
;e::
vNum := 100000000 ;10^8
vText := ""
VarSetCapacity(vText, vNum*2, 1)
vText := StrReplace(vText, Chr(257), "a") "b"
Loop, 2
{
;test 1 - case sensitive
vTickCount1 := A_TickCount
vPos := InStr(vText, "b", 1)
vTickCount2 := A_TickCount
MsgBox % vTime1 := vTickCount2-vTickCount1
;test 2 - case insensitive
vTickCount1 := A_TickCount
vPos := InStr(vText, "b", 0)
vTickCount2 := A_TickCount
MsgBox % vTime2 := vTickCount2-vTickCount1
MsgBox % Clipboard := vTime1 " " vTime2 ;125 94, 141 94
}
Return
==================================================
Comments on list comparison:
For a spellchecker or looking a up word in a list:
if there are 100 words or fewer, I use InStr, e.g.
if !InStr(vSpellListText, "`n" A_LoopField "`n")
For longer lists, if order doesn't matter:
I sort the needles list, (the haystack list is already sorted,)
and parse the 2 lists simultaneously.
For longer lists, if order does matter:
I prepend/append numbers to the needle lists,
sort the needle/haystack lists together,
possibly using a custom filter,
parse to find matches/non-matches,
(and append needle items to a new list with their match results,)
and restore the original order to the new needles results list.