2 comments

[ 2.9 ms ] story [ 6.7 ms ] thread
First of all, this is really comparison of regexp packages. PCRE (am I correct that it's used in perl?) written in C vs re2 written in Go.

On related topic, in this case utf8 is not needed so switching to []byte oriented api is good idea (and as an added benefit - slices are cheaper to copy then strings) - see comparison https://gist.github.com/tumdum/83581aee2693a60f5133

If I understand correctly, pcre = Perl Compatible Regular Expressions. While that library attempts to be able to do most of what perl regex can do (or could do a while ago as it doesn't seem to keep up with modern Perl versions), it doesn't implement the entirety. Perl itself doesn't use that library, but is an optimized engine built into perl that provides the basis that pcre is based off of.

It's not surprising that the Perl is faster, as it is all in C, and has had lots of optimizations over a few decades. I've had similar results between perl and things like grep, Ruby, python etc. Perl comes out on top!