Regex benchmark

198 views
Skip to first unread message

Tuom Larsen

unread,
Feb 11, 2015, 8:02:14 AM2/11/15
to golan...@googlegroups.com
Dear list!

I recently looked at the "regex-dna" [1] benchmark at Computer Language Benchmarks Game and apparently Go runs 28x slower (145.22s / 5.22s) than C++ despite both using re2.

Please, can someone help me understand the reason for such a difference?

thwd

unread,
Feb 11, 2015, 8:14:02 AM2/11/15
to golan...@googlegroups.com
On Wednesday, February 11, 2015 at 2:02:14 PM UTC+1, Tuom Larsen wrote:
I recently looked at the "regex-dna" [1] benchmark at Computer Language Benchmarks Game and apparently Go runs 28x slower (145.22s / 5.22s) than C++ despite both using re2.

Please, can someone help me understand the reason for such a difference?

Go only uses re2's syntax, not the library. Go's regexp package only does minor optimizations on expressions and builds a finite automaton at runtime.

Speculation: C++ probably uses metaprogramming (templates) to build the automatons at compile time, taknig full advantage of a compiler's optimization capabilities.

Ian Lance Taylor

unread,
Feb 11, 2015, 10:08:22 AM2/11/15
to Tuom Larsen, golang-nuts
On Wed, Feb 11, 2015 at 5:02 AM, Tuom Larsen <tuom....@gmail.com> wrote:
>
> I recently looked at the "regex-dna" [1] benchmark at Computer Language
> Benchmarks Game and apparently Go runs 28x slower (145.22s / 5.22s) than C++
> despite both using re2.
>
> Please, can someone help me understand the reason for such a difference?

They both use re2 but they use entirely different implementations of
it. The C++ re2 includes several optimizations that the Go version
does not.

Ian
Reply all
Reply to author
Forward
0 new messages