Regex vs. RegexMBS

@Kem Tekinay recently mentioned that RegexMBS is much faster than Xojo’s Regex. I started to test on a very simple piece of code.

The original code where I need to check if some text of 100 chars is Base64Encoded:

[code]Private Function IsReallyBase64Encoded(theLeft as String) as Boolean

theLeft = ReplaceLineEndingsMBS(theLeft, “”, True)
dim theStart as integer
dim theRegex as new Regex
theRegex.options.greedy = false
theRegex.searchPattern = “\s”
dim theRegexMatch as RegExMatch = theRegex.search(theLeft)
if theRegexMatch = nil then Return true

End Function[/code]

New code with RegexMBS:

[code]theLeft = ReplaceLineEndingsMBS(theLeft, “”, True)
dim theRegexMBS as new RegExMBS
theRegexMBS.CompileOptionCaseLess = True
theRegexMBS.CompileOptionUngreedy = true

dim MBSResult as Boolean
if theRegexMBS.Compile("\s") then
MBSResult = not theRegexMBS.Match(theLeft)
end if

Return MBSResult[/code]

I archived a couple of thousand emails. To my surprise that little change of code made the archival 10 seconds slower with MBS.

So when is MBS faster? For larger strings only? Why is MBS slower here?

Try saving the object, perhaps in a static, instead of recreating it each time. But I expect that will make them run about the same.

To see the speed difference, loop through a single long string that will have, say, 100 matches in it.

is caseless also set for Xojo’s class?

@Christian Schmitz: I copied the code as is.

@Kem Tekinay : I’ll try with a static variable. The timing was 2:55 original, 3:07 with MBS, 3:48 with MBS and added “study”. 3k emails where I need to check the base64 encoded parts.