Live data from Hacker News

How come PHP seems so much faster than Rust?

reddit.com

11–20 of 116 posts

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

#11
While this discussion boils down to the efficiency of the underlying regex engines for PHP and Rust, it does highlight (to me) why PHP is so popular: in the hands of average programmers, PHP is quick to write and fast (enough) to execute.

I personally believe it's ubiquity is well-deserved, and I actually like it as a language despite all its quirks (which exist in almost every language I've come across)!

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

#13
post #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 :^)

To be fair, the benchmarks game PHP script does quite more work that just matching a regexp, like forking into multiple interpreters (which can't be that fast) and communicating through a message queue.

So any speed difference between Rust's and PCRE/PHP gets lost among the noise.

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

#15
post #14

I maybe wrong but rust uses a dfa regex engine, while pcre uses backtracking. So in theory rust's regex engine should be faster...

Seems like the flamegraph he took of his Rust program shows it using backtracking, maybe for the specific regexp he is using it's unable to use a DFA: https://i.imgur.com/9lx42Tu.png

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

#16
post #11

While this discussion boils down to the efficiency of the underlying regex engines for PHP and Rust, it does highlight (to me) why PHP is so popular: in the hands of average programmers, PHP is quick to write and fast (enough) to execute. I personally believe it's ubiquity is well-deserved, and I actually like it as a language despite all its quirks (which exist in almost every language I've come across)!

I don't like it from the security perspective, looking at just how many vulnerabilities PHP-based software has had, it's too trivial to create a XSS, SQLi, CSRF, LFI, RCE and many other classes of vulnerabilities. I think there are better options out there than on average give better results. Maybe it's just incredible selection bias I'm encountering \shrug.

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

#17
post #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 ju…

> 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.

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

#18
post #11

While this discussion boils down to the efficiency of the underlying regex engines for PHP and Rust, it does highlight (to me) why PHP is so popular: in the hands of average programmers, PHP is quick to write and fast (enough) to execute. I personally believe it's ubiquity is well-deserved, and I actually like it as a language despite all its quirks (which exist in almost every language I've come across)!

I don't like it from the security perspective, looking at just how many vulnerabilities PHP-based software has had, it's too trivial to create a XSS, SQLi, CSRF, LFI, RCE and many other classes of vulnerabilities. I think there are better options out there than on average give better results. Maybe it's just incredible selection bias I'm encountering \ shrug .

But plenty of those vulnerabilities are not the fault of the language but the frameworks written by others. You can just as easily create SQL injection attacks in a Rust program or Ruby program. You can just as easily introduce XSS/CSRF problems in any of them. Etc.

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

#19
post #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 ju…

This 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.

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

#20
post #11

While this discussion boils down to the efficiency of the underlying regex engines for PHP and Rust, it does highlight (to me) why PHP is so popular: in the hands of average programmers, PHP is quick to write and fast (enough) to execute. I personally believe it's ubiquity is well-deserved, and I actually like it as a language despite all its quirks (which exist in almost every language I've come across)!

I don't like it from the security perspective, looking at just how many vulnerabilities PHP-based software has had, it's too trivial to create a XSS, SQLi, CSRF, LFI, RCE and many other classes of vulnerabilities. I think there are better options out there than on average give better results. Maybe it's just incredible selection bias I'm encountering \ shrug .

It’s really easy to write PHP, which means that people who don’t know about escaping input write PHP.

While there are some web-focussed languages (vs frameworks) that deliberately make it hard for you to write that sort of code, barely anyone uses them.

Post reply on HN