But recently I saw someone complain that "findstring" was slow, so I wrote this simple routine to count occurrences of a word to see just how slow it really was. Seems quite fast to me, or maybe its just the clock speed of my CPU that gives it speed. I let you be the judge.
I used The constitution of the US as a text source for my word search.
I just right clicked this link and used the [Save link as] option to download the Titan Bug.txt file : https://www.gutenberg.org/cache/epub/5/pg5.txt
Code: Select all
; text source: https://www.gutenberg.org/cache/epub/5/pg5.txt
Debug FileSize("D:\TEMP\TEMP\Titan Bug.txt")
search$ = "free"
ReadFile(0,"D:\TEMP\TEMP\Titan Bug.txt",#PB_File_SharedRead | #PB_Ascii)
Buffer.s = ReadString(o,#PB_File_IgnoreEOL)
CloseFile(0)
time = ElapsedMilliseconds()
L = Len(buffer)
Debug L
P = 1
While P < L
P = FindString(buffer,search$,P+1)
If P
C +1
Else
Break
EndIf
Wend
Debug C
Debug ElapsedMilliseconds() - time
time = ElapsedMilliseconds()
Debug CountString(buffer,search$)
Debug ElapsedMilliseconds() - time