Code: Select all
ImportC "msvcrt.lib"
strstr(*lpFirst, *lpSrch) ; Finds the first occurrence of a substring within a string. The comparison is case sensitive.
EndImport
Macro FindString2(String, StringToFind, StartPosition)
(strstr(@String + StartPosition - 1, @StringToFind) + 1 - @String)
EndMacro
#Tries = 10000000
String$ = "The quick brown fox jumped over the lazy dog"
t0 = ElapsedMilliseconds()
For i = 0 To #Tries : p = FindString(String$, "lazy", 7) : Next
t1 = ElapsedMilliseconds() - t0
t0 = ElapsedMilliseconds()
For i = 0 To #Tries : p = FindString2(String$, "lazy", 7) : Next
t2 = ElapsedMilliseconds() - t0
MessageRequester("Results", "FindString() : " + Str(t1) + #LF$ + "StrStr() : " + Str(t2))
Results on my AthlonXP 2800+ (2.08Ghz) :
FindString() : 2062ms
StrStr() : 1360ms