Live data from Hacker News

How come PHP seems so much faster than Rust?

reddit.com

21–30 of 116 posts

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

#21
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)!

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

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

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

[deleted]

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

#24
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)!

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

Indeed. I think most developers don't understand how amazing PHP was compared to the competition and just how fast it acquired new features during those early years.

It was a scripting engine with a such a thin layer of C that it could easily and quickly incorporate the huge number of open source C libraries that existed at the time.

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

#25
post #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.

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

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

#26

Earlier quoted context omitted.

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.

> You can just a easily create SQL injection attacks in a Rust program

I disagree, mostly on the grounds that string concatenation isn't very convenient, so it tends to be easier to do things "the right way" instead of hacking things together. Yes, you can do string concatenation using something like `format!(...)`, but at that point it's really similar to the correct solution that it's not really what you'd reach for by default.

And yeah, the community here is a huge part of it, and IMO languages can and should be judged by their communities. If a language's community promotes insecure solutions, that's a language that I don't want to use at my company because I don't want my employees following that example.

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

#27
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)!

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

>for a long while [PHP] was the only viable language for developing web applications.

That is not what I remember. CGI existed before PHP (1994), and was used extensively for web apps (ebay still appears to use it to this day). Also, mod_perl and Java Servlets were introduced around the same time, circa 1996, so I don't think it's correct to say PHP had a monopoly on web apps "for a long while".

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

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

Your argument is a form of survivorship bias. You're not acknowledging all of the gaping security flaws in contemporary web-development frameworks. People were writing sloppy PHP before CSRF and XSS were even invented. Yet somehow, Python, Ruby and NodeJS have all had numerous CVEs despite those attack vectors being well known at the time a given framework was written.

You think SQLi was bad? You should spend some time thinking about the numerous attack vectors available today in nearly every GraphQL implementation where programmers can't move fast enough in adding it to their stack. Data exfiltration is no longer a flaw but a feature.

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

#29
post #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.

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

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

#30

Earlier quoted context omitted.

PHP isn't popular because it's easy, it's popular because for a long while it was the only viable language for developing web applications.

>for a long while [PHP] was the only viable language for developing web applications. That is not what I remember. CGI existed before PHP (1994), and was used extensively for web apps (ebay still appears to use it to this day). Also, mod_perl and Java Servlets were introduced around the same time, circa 1996, so I don't think it's correct to say PHP had a monopoly on web apps "for a long while".

Coldfusion was also a thing around that time. Flash sites as well.
Post reply on HN