3 comments

[ 2.5 ms ] story [ 19.9 ms ] thread
Regarding performance Rust is the loser in this comparison. The regex crate documentation addresses this issue and says this is because of a lack of optimization. Generally I really like the fresh approach that Rust takes on the regex topic. I can't explain it better than the docs:

   This crate provides a native implementation of regular expressions 
   that is heavily based on RE2 both in syntax and in implementation. 
   Notably, backreferences and arbitrary lookahead/lookbehind assertions 
   are not provided. In return, regular expression searching provided by 
   this package has excellent worst-case performance. 

   [...]

   Rust's compile-time meta-programming facilities provide a way to write 
   a regex! macro which compiles regular expressions when your program 
   compiles. Said differently, if you only use regex! to build regular 
   expressions in your program, then your program cannot compile with 
   an invalid regular expression. Moreover, the regex! macro compiles the 
   given expression to native Rust code, which ideally makes it faster. 
   Unfortunately (or fortunately), the dynamic implementation has had a 
   lot more optimization work put into it currently, so it is faster than 
   the regex! macro in most cases.
http://doc.rust-lang.org/regex/regex/index.html
The regex crate actually has quite a bit of optimization, which is why it's #1 on the benchmark game. In the OP, it looks like Rust is holding its own to me.

Just because Rust's regexes use automata doesn't mean they have to be slow. :-) It can be tricky to make them fast, but RE2 proves that it is possible!