5 ms·
This is a little silly. The two programs are so simple that it's probably just testing the speed of the regex engines used by the two languages. Since PHP use
by kelnos 7y ago
This is a little silly. The two programs are so simple that it's probably just testing the speed of the regex engines used by the two languages. Since PHP uses PCRE (a C library that has been around for quite a long time), you'd expect it to be fast. I'm impressed that marshaling back and forth across the FFI boundary isn't causing more slowness, but perhaps it is, and the real issue is that rust's regex engine is just painfully slow.
The only way to know for sure would be to profile each bit to see what dominates: the file I/O? The regex matching? The FFI? The printing to stdout?
Also, looks like there is a rust wrapper for PCRE[0]; might be interesting to try it to get a more apples-to-apples comparison.
[0] https://github.com/cadencemarseille/rust-pcre https://github.com/cadencemarseille/rust-pcre
- aksx 7y ago> This is a little silly. Is it though? I interpreted question the following way. "Rust is a tool in my tool box, when the reason for picking it over other tools isn't demonstrably true, what am i doing wrong?" I agree with the rest of your comment, just not with calling the OP or their question silly.
- beatgammit 7y agoThe reason for picking it is for memory safety as well as performance. If your problem involves a lot of regex and memory safety isn't as critical, then feel free to pick a language with good regular expression libraries. If regular expressions are a smaller part of your problem you're solving, looking at overall performance is better than benchmarks like this.
- gtirloni 7y agoI'd never know that if this post didn't exist, so I don't think the investigation is silly at all.
- smaccona 7y agoYour conclusion is correct, but the reason I take issue is that that’s not the thesis of OP. OP’s original subject/headline suggests that, or questions why, Rust is generally slow vs PHP, and uses a regex example as the “proof”. A person who didn’t read the Reddit comments, or who is less versed in critical thinking, may accept the example as a valid proof of the thesis, instead of simply noting the fact that Rust may not be as good at regex as it is at other things. If the Reddit subject was “Rust is worse than PHP at regex”, nobody would bat an eyelid and the resulting conversational threads would have a different tenor (and your conclusion would and should be the same).
- kelnos 7y agoYou're right, and in hindsight I regret my tone there.
- eMSF 7y agoThis is more than a little silly, and simply shows that the self-proclaimed PHP developer (who is "not surprised that PHP is 'fast'") has little to no idea what is costly in execution time, even in such a tiny example of a program, and has no idea how to figure that out.
- jlarocco 7y agoWhat's silly is that somebody asked a legitimate question in good faith with code samples and everything, and you responded with an ad-hominem attack with no useful information.
- fortran77 7y agoDidn't someone here say we should judge a language by its community? Well the Rust community is not very nice.
- eMSF 7y agoAs one that has never, ever written a single program in Rust, am I part of a "Rust community"? But I agree, I'm not nice at all, indeed.
- toonspin 7y agoOP of the Reddit post here. I made a Hacker News account just to come here and reply to you, because I would like to set the record straight in this regard. I have always consistently found the Rust community to be nothing but amazingly helpful and friendly. I've posted in the Rust subreddit before in a different account and got the same helpful and friendly responses I did this time. If we should judge a language by its community, then I, for one, wholeheartedly recommend Rust. There was actually another post recently where someone asked a similar question only about Kotlin, and there ended up being this collaborative effort where people kept rewriting and optimizing both his Kotlin and his Rust code. Check it out: https://www.reddit.com/r/rust/comments/d85gyh/why_is_this_slow/ https://www.reddit.com/r/rust/comments/d85gyh/why_is_this_sl... There's an update too: https://www.reddit.com/r/rust/comments/d8kew3/why_is_this_slow_update/ https://www.reddit.com/r/rust/comments/d8kew3/why_is_this_sl...
- deleted 7y ago[deleted]
- lpil 7y ago> and the real issue is that rust's regex engine is just painfully slow. The benchmarks game suggests that it's quite fast: https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/regexredux.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...