This true for Procedure, but it's not for built-in functions, so there is no penalities here.srod wrote:Freebasic passes strings by reference so only passes the address to a function as opposed to PB in which the function itself makes a copy of the string which has been passed. This will inevitably slow things down.
About the performance, some time is lost to StrLen() computation, which is needed to ensure the startposition is not above the end of string (it's done even with a 0 start position which is dumb, so I changed that and it resulted to a 60% gain). About the comparison to other languages, some use 'tricks' to perform well in 'real wold' scenario. It's the Python case, which looks at the end of the string first (which is exactly your case). It's indeed a special case. PB uses the 'strstr' C function which always starts to the start of the string, so your benchmark is basically the worste ever for PB, as the result is at the very end. Try to find a a string which is not found in other language, I'm curious to see the results:
Code: Select all
s.s = Space(1000000) + "!"
t = ElapsedMilliseconds()
For i = 1 To 1000
x = FindString(s, "x")
Next
MessageRequester("", "" + Str(ElapsedMilliseconds() - t))
t = ElapsedMilliseconds()
For i = 1 To 1000
x = FindString(s, "x", 0, #PB_String_NoCase)
Next
MessageRequester("", "" + Str(ElapsedMilliseconds() - t))