4 ms·
You can look at a well known (but not very complete) benchmark comparison here [0], rust wins, the fastest boost program is c++ g++ #3 and takes 8.5 times as lo
by gpm 10y ago
You can look at a well known (but not very complete) benchmark comparison here [0], rust wins, the fastest boost program is c++ g++ #3 and takes 8.5 times as long, the fastest c++ implementation (using re2) takes twice as long.
I don't know of a fuzz comparison, but there has been fuzzing done on the rust library without finding anything bad, e.g. see this issue [1].
[0] http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=regexdna http://benchmarksgame.alioth.debian.org/u64q/performance.php...
[1] https://github.com/rust-lang/regex/issues/203 https://github.com/rust-lang/regex/issues/203
- justinmk 10y ago> benchmark comparison here [0], rust wins, the fastest boost program is c++ g++ #3 and takes 8.5 times as long With PHP at #2? Doesn't seem credible, or the thing being tested isn't meaningfully language-dependent.
- dbaupp 10y agoIndeed, it is the regex implementation that is being tested (and so the language of that implementation is relevant), which is exactly what this discussion is about and also why that comment is careful to be specific about which programs are using which regex implementation.
- beering 10y agoIt's testing each language's implementation of regexes. A lot of the languages are probably linking in a regex library written in C or C++ anyways. It's evidence that if you're writing something that's heavy on regexes, any slowdown probably isn't due to the language itself but its library implementation.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- barkingcat 10y agoPHP pcre is implemented in c https://github.com/php/php-src/blob/master/ext/pcre/php_pcre.c https://github.com/php/php-src/blob/master/ext/pcre/php_pcre...
- deleted 10y ago[deleted]
- Skunkleton 10y agoWhy not? They are all basically wrappers around ASM.
- wbond 10y agoConsidering the C implementation using PCRE is 4.1x Rust, whereas PHP (implemented in C, also using PCRE) is 1.2x Rust, that makes me think that this benchmark is… unhelpful at best. The fastest C implementation uses TCL’s simplified regexes. However, http://lh3lh3.users.sourceforge.net/reb.shtml http://lh3lh3.users.sourceforge.net/reb.shtml indicates that they found generally oniguruma and re2 trounce TCL. Some other comparisons of regex engine performance is at http://sljit.sourceforge.net/regex_perf.html http://sljit.sourceforge.net/regex_perf.html. Unfortunately neither of these are new enough to include Rust. One of the big pieces that can easily be glossed over, especially during performance comparisons, is unicode handling.
- kibwen 10y ago> One of the big pieces that can easily be glossed over, especially during performance comparisons, is unicode handling. Patterns in Rust's regex library are Unicode-aware by default: https://doc.rust-lang.org/regex/regex/index.html#unicode https://doc.rust-lang.org/regex/regex/index.html#unicode
- burntsushi 10y agoThe regex-dna benchmark biases toward regex engines with aggressive literal optimizations. Namely, there are 21 distinct regexes in the benchmark. Of those 21, only 1 of them actually uses Rust's core regex engine. The rest are compiled down to literal searches. Even in that one case, literal optimizations are used to speed it up. I'm not familiar with Tcl's engine, but if it also applies aggressive literal optimizations, then that could explain its performance. However, given a more fine-grained analysis of regex-dna[1], that seems unlikely. The C program is large, so perhaps there is more to it than meets the eye. The perf difference between PHP w/ PCRE and C w/ PCRE has always perplexed me. But there are... so many variables. Maybe PHP enables JIT in PCRE (the C program does not), or perhaps PHP's preg_replace is doing something clever, e.g., by combining all of the replacement regexes into one.[2] > One of the big pieces that can easily be glossed over, especially during performance comparisons, is unicode handling. Indeed. The regex-dna benchmark does not require any Unicode handling at all. It's a strictly ASCII based benchmark. If your regex engine uses finite state machines, then one can typically build your encoding into the machines themselves, which results in little or no performance degradation in matching in the common case. (The cases where it matters is if your regex is large, e.g., `\pL{100}` is large indeed.) [1] - https://github.com/rust-lang/regex/blob/master/bench/log/05/tcl-vs-rust#L39-L59 https://github.com/rust-lang/regex/blob/master/bench/log/05/... [2] - https://github.com/rust-lang/regex/blob/master/examples/shootout-regex-dna-cheat.rs https://github.com/rust-lang/regex/blob/master/examples/shoo...
- kibwen 10y agoIssue 203 indicates that the fuzzing was done, but doesn't link to the issues that were uncovered by fuzzing. The PR at https://github.com/rust-lang/regex/pull/262 https://github.com/rust-lang/regex/pull/262 does: one infinite loop, four panics, and one instance of the NFA reporting the wrong position of a match.