<p>I was going through <a href="https://benchmarksgame.alioth.debian.org/u64q/regexredux.html">this</a> for the hell of it, and I saw that Go is generally quite quick. But there were a few outliers, and the most notable one for me was the regex code which was blown away by a ton of languages.</p>
<hr/>**评论:**<br/><br/>shovelpost: <pre><p>First of all most other languages use the C implementation so Go is losing to C.</p>
<p>Also as far as I remember, Go's regex is guaranteed to finish in time linear to the length of the input which protects from ReDoS attacks. That feature is really important for production services and while in terms of speed it might not be the fastest for certain regexps, it's still fast enough and safer on top. Meanwhile the Go team is working to <a href="https://github.com/golang/go/issues/11646" rel="nofollow">improve it even more</a>.</p>
<p>Edit: Found some official info by <a href="https://github.com/golang/go/issues/19629#issuecomment-288152974" rel="nofollow">Ian Lance Taylor</a>:</p>
<blockquote>
<p>As you say, in a language like Python, the regexp engine is implemented in C. So you are comparing a somewhat tuned Go implementation with a highly tuned C implementation. You also need to consider the characteristics of the engine. Go has chosen to follow the re2 path (not surprising, since Russ Cox is a major author of both Go and re2). re2 has much better performance characteristics than some other regexp engines, in that it never has an exponential slowdown, but that comes at a cost for other regexps (<a href="https://swtch.com/%7Ersc/regexp/" rel="nofollow">https://swtch.com/~rsc/regexp/</a>).</p>
</blockquote></pre>soapysops: <pre><p>That is interesting.</p>
<p>It's not really an "apples to apples" comparison to some of those languages because they implement Perl style regular expressions instead of just regular expressions.</p>
<p>It looks like Go's implementation could use some more optimization. Rust's regular expression engine is way faster even though they use the same general design.</p></pre>qspec02: <pre><p>Yeah, I thought that whole site was pretty interesting. Generally speaking, Go performed admirably, but regex definitely stood out.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传