
Regular expressions: Rust vs. F# vs. Scala vs. D - yawniek
http://vaskir.blogspot.com/2015/09/regular-expressions-rust-vs-f.html
======
weinzierl
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](http://doc.rust-
lang.org/regex/regex/index.html)

~~~
burntsushi
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!

------
chenglou
Would be nice to have JS' speed (V8)! Last time I checked they compile the
regex into some really clever heuristics. I wouldn't be surprised if the speed
is on par or faster than what's here.

[http://blog.chromium.org/2009/02/irregexp-google-chromes-
new...](http://blog.chromium.org/2009/02/irregexp-google-chromes-new-
regexp.html?m=1)

