ErosOlmi
15-10-2018, 22:45
thinBasic 1.10.5 introduced some new FAST version of standard string functions that ... are in some cases thousands of times faster than they standard counterpart
FAST function versions are like standard one but with an F in the name. Example: MIDF$, LEFTF$, RIGHTF$, LENF, GRABF$, PARSEF$, PARSECOUNTF
The bigger the string, the better will be results.
Below example show their usage and results on my PC are the following:
Size of string: 11,000,000 bytes
Time to perform 100 mid$: 0.941708
Time to perform 100 midF$: 0.000136
6924.324x faster
Time to perform 100 left$: 0.916229
Time to perform 100 leftF$: 0.000154
5949.539x faster
Time to perform 100 right$: 0.906004
Time to perform 100 rightF$: 0.000173
5237.017x faster
Time to perform 100 len$: 1.841468
Time to perform 100 lenF$: 0.000065
28330.277x faster
Time to perform 100 parse$: 0.849208
Time to perform 100 parseF$: 0.000356
2385.416x faster
Time to perform 100 grab$: 0.863512
Time to perform 100 grabF$: 0.000425
2031.793x faster
Example
#MinVersion 1.10.5
uses "console"
ext delta, deltaF
string buffer
buffer = repeat$(1000000, "(BCDEFGHI),")
printl "Size of string: " + format$(len(buffer), "#,") + " bytes"
printl
string x
long length
long n
hirestimer_init
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = Mid$(buffer, 1000, 10)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 mid$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = MidF$(buffer, 1000, 10)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 midF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = left$(buffer, 1000)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 left$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = leftF$(buffer, 1000)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 leftF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = right$(buffer, 1000)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 right$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = rightF$(buffer, 1000)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 rightF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
length = len(buffer)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 len$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
length = lenf(buffer)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 lenF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = parse$(buffer, ",", n)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 parse$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = parsef$(buffer, ",", n)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 parseF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = grab$(buffer, "(", ")", n)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 grab$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = grabf$(buffer, "(", ")", n)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 grabF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
printl "---Press a key to end---"
WaitKey
FAST function versions are like standard one but with an F in the name. Example: MIDF$, LEFTF$, RIGHTF$, LENF, GRABF$, PARSEF$, PARSECOUNTF
The bigger the string, the better will be results.
Below example show their usage and results on my PC are the following:
Size of string: 11,000,000 bytes
Time to perform 100 mid$: 0.941708
Time to perform 100 midF$: 0.000136
6924.324x faster
Time to perform 100 left$: 0.916229
Time to perform 100 leftF$: 0.000154
5949.539x faster
Time to perform 100 right$: 0.906004
Time to perform 100 rightF$: 0.000173
5237.017x faster
Time to perform 100 len$: 1.841468
Time to perform 100 lenF$: 0.000065
28330.277x faster
Time to perform 100 parse$: 0.849208
Time to perform 100 parseF$: 0.000356
2385.416x faster
Time to perform 100 grab$: 0.863512
Time to perform 100 grabF$: 0.000425
2031.793x faster
Example
#MinVersion 1.10.5
uses "console"
ext delta, deltaF
string buffer
buffer = repeat$(1000000, "(BCDEFGHI),")
printl "Size of string: " + format$(len(buffer), "#,") + " bytes"
printl
string x
long length
long n
hirestimer_init
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = Mid$(buffer, 1000, 10)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 mid$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = MidF$(buffer, 1000, 10)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 midF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = left$(buffer, 1000)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 left$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = leftF$(buffer, 1000)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 leftF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = right$(buffer, 1000)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 right$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = rightF$(buffer, 1000)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 rightF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
length = len(buffer)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 len$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
length = lenf(buffer)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 lenF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = parse$(buffer, ",", n)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 parse$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = parsef$(buffer, ",", n)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 parseF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
hirestimer_get
for n = 1 to 100
x = grab$(buffer, "(", ")", n)
Next
delta = hirestimer_delta/1000000
PrintL "Time to perform 100 grab$: ", format$(delta, "#0.000000")
hirestimer_get
for n = 1 to 100
x = grabf$(buffer, "(", ")", n)
Next
deltaF = hirestimer_delta/1000000
PrintL "Time to perform 100 grabF$:", format$(deltaF, "#0.000000")
PrintL format$(delta/deltaF, "#.000") + "x faster"
PrintL
' ---- ---- ---- ---- ---- ----
printl "---Press a key to end---"
WaitKey