Pay attention: there are some FAST version of some standard functions. For example:
LEN and LENF
LEFT$ and LEFTF$
MID$ and MIDF$
RIGHT$ and RIGHTF$
GRAB$ and GRABF$
The difference is that the STANDARD version of the function accepts any string expression while the FAST version of the function accepts only scalar dynamic string variables.
Why is FAST? Because instead of parsing a string expression and allocate memory for it, it just use a pointer to the scalar string variable and it is super super fast and no memory allocation takes place.
For example if you pass 100MB string to MID$ it created a new copy of your 100MB string, perform the MID$ function, de-allocate the copy of the 100MB string and return
Very inefficient
While MIDF$ just perform the MID using the memory area of the scalar string variable passed.
It is like the difference of passing a parameter BYCOPY or BYREF
An example?
Check by yourself how much faster it is
uses "console"
Double T1, T2
'---Allocate a 10MB string
string S(2)
s(1) = repeat$(1000000, "ABCDEFGHIJ")
string X
Long L
long N
Print "Time to perform 100 times MID$ + LEN on a 10MB string:", "..."
T1 = Timer
for n = 1 to 100
x = Mid$(s(1), 1000, 10)
x = Left$(s(1), 10)
x = Right$(s(1), 10)
L = len(s(1))
Next
T2 = Timer
PrintL format$(T2-T1, "#0.000000")
Print "Time to perform 100K times fast mid MIDF$ + LENF on a 10MB string:", "..."
T1 = Timer
for n = 1 to 100000
x = MidF$(s(1), 1000, 10)
x = Leftf$(s(1), 10)
x = Rightf$(s(1), 10)
L = lenF(s(1))
Next
T2 = Timer
PrintL format$(T2-T1, "#0.000000")
PrintL
printl "---Press a key to continue---"
WaitKey
Bookmarks