Live data from Hacker News

How come PHP seems so much faster than Rust?

reddit.com

1–10 of 116 posts

Re: How come PHP seems so much faster than Rust?

#4
The top reply says "Don't underestimate PHP when regexes are involved." and linked a benchmark [1].

But in that benchmark apparently Rust is faster than PHP (The slowest "Rust #2" is 2.45 sec. while PHP is 2.80 sec. He also mentioned "PCRE", but the ones with Perl in name are even much more slower [the fastest being 14.95 sec.]).

Did I miss his point by linking that benchmark, or did I interpret the benchmark wrong?

[1]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re: How come PHP seems so much faster than Rust?

#5
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

Re: How come PHP seems so much faster than Rust?

#6

The top reply says "Don't underestimate PHP when regexes are involved." and linked a benchmark [1]. But in that benchmark apparently Rust is faster than PHP (The slowest "Rust #2" is 2.45 sec. while PHP is 2.80 sec. He also mentioned "PCRE", but the ones with Perl in name are even much more slower [the fastest being 14.95 sec.]). Did I miss his point by linking that benchmark, or did I interpret the benchmark wrong?…

One could expect PHP to be a lot slower, the benchmark shows it can keep up. PCRE is the name of the regex library used by (among others) PHP, which is why PHP is good at regex.

Other comments address why the Rust program is not optimal.

Re: How come PHP seems so much faster than Rust?

#8

The top reply says "Don't underestimate PHP when regexes are involved." and linked a benchmark [1]. But in that benchmark apparently Rust is faster than PHP (The slowest "Rust #2" is 2.45 sec. while PHP is 2.80 sec. He also mentioned "PCRE", but the ones with Perl in name are even much more slower [the fastest being 14.95 sec.]). Did I miss his point by linking that benchmark, or did I interpret the benchmark wrong?…

I guess the poster didnt saw Rust being faster, only that PHP is pretty fast, or at least not slow (so it should be underestimated).

Id take that slowdown any day just not having to touch Rust though :^)

Re: How come PHP seems so much faster than Rust?

#9
Random guess:

There will be some difference in the regex engine speed, because PCRE is very fast in common cases.

But doing a single regex match is not that much work, so it probably boils down to I/O.

And PHP might use extra buffering to get better throughput for the common "stream a file" scenario.

Similar question with Python being faster than C++:

https://stackoverflow.com/questions/9371238/why-is-reading-l...

Post reply on HN