« MBS Xojo Plugins, ver… | Home | xDev Magazine 20.3 »

Iterate with PCRE2

For our new PCRE2CodeMBS class, we add a new Matches method. It returns an iterator, so you can use it with a for-each loop in Xojo:

Sub test() Dim rx As New PCRE2CompilerMBS rx.CaseLess = True rx.DotAll = False rx.Ungreedy = False rx.NewLine = rx.kNewLineAnyCRLF rx.Multiline = True rx.Pattern = kMarkerPattern Dim code As PCRE2CodeMBS = rx.Compile If UseJIT Then code.JITCompile(code.kJITComplete) End If for each MatchData as PCRE2MatchDataMBS in code.Matches(TestString, 0) foundCount = foundCount + 1 next End Sub

One of the key elements ot reach best performance is to reuse the PCRE2CodeMBS objects and avoid compilation as much as you can. Second, you avoid creating PCRE2MatchDataMBS objects and reuse them. The iterator does that by default for you.

Let us show you the numbers from our benchmark:

RegEx XojoRegEx MBSPCRE2PCRE2+JITPCRE2 IteratorPCRE2 Iterator+JIT
Match 500 in 1 MB171317347835212663231277
Match 500 in 10 MB17112413062730742928305421063
Match 5000 in 1 MB1642035323437764343660478
Match 5000 in 10 MB1683419830906312001363311571456

Tests made with MBS Xojo Plugins 22.2pr and Xojo 2022r2.1 on a current MacBook Pro. The Xojo value is a 10 times average while the MBS calls are averaged over running 100 times. But at the quick turn around times of the compiled code, it gets hard to measure!

If you haven't tried yet, please give the PCRE2 classes with just-in-time compiler a try. They are often 10 times faster compared to our already quick RegExMBS class.

The biggest plugin in space...
05 05 22 - 14:13