5 ms·
> How is PHP remotely comparable to Python Faster. > Perl More readable and writeable, and probably more popular in the past fifteen years. > Ruby Again fa
by aasasd 5y ago
> How is PHP remotely comparable to Python
Faster.
> Perl
More readable and writeable, and probably more popular in the past fifteen years.
> Ruby
Again faster.
- gizdan 5y agoI never thought those reasons would ever be valid until PHP 7.
- aasasd 5y agoPHP long had decent performance, since version 4 iirc when it borrowed the bytecode approach from Perl and afterwards afaik was pretty much on par with it. Remember that even with FastCGI the vastly prevailing model of execution for PHP is to start the script just from the bytecode cache every time and destroy everything when it ends. Long-living async apps like with ReactPHP never became any kind of popular, and still PHP is likely the most popular serverside environment on the web (if only because of Wordpress). Perl and PHP are both likely way better for personal productivity scripting than Python or Ruby, in terms of not waiting for them to get going already. Personally I would like it very much if Lua became as popular, though the absence of proper `null` is bothersome for data exchange.
- cutler 5y agoIf you're going to compare Perl with Ruby make it Perl + Moose then redo your benchmarks. Otherwise it's an apples to oranges comparison as Ruby has built-in OOP. Ruby was built on top of the best bits of Perl and with its blocks and metaprogramming it is arguably the most advanced scripting language. Python fails to match Perl and Ruby due to its half-assed lambdas.
- aasasd 5y agoA correction: just checked startup time of PHP vs Perl on Mac, and Perl is a lot faster, so turns out it's not quite ‘on par’.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- cutler 5y ago> More readable and writeable, and probably more popular in the past fifteen years. You're confusing PHP's general popularity for web development with it's popularity as a command-line scripting language. There's no way PHP is more popular than Perl for non-web scripting. Unlike Perl, PHP was never designed as a general purpose language. Try writing a PHP script which has to parse command line options. It ain't pretty. Python, Ruby and Perl were designed for this. PHP was not. PHP is extremely fast for scripts written in raw, procedural PHP but its shared nothing design makes it a liability with large frameworks such as Laravel and Symfony. In many tech empower benchmarks Django and Rails are listed ahead of Laravel.
- aasasd 5y ago> Try writing a PHP script which has to parse command line options. It ain't pretty. Python, Ruby and Perl were designed for this. PHP was not. Worked just fine at the job where we had a ton of serverside daemons. You're saying like splitting a few strings and putting them in a dict is black magic, and as if Python, Ruby and Perl don't use some libs for that, which (hopefully) evolved over some time. > its shared nothing design makes it a liability with large frameworks such as Laravel and Symfony. In many tech empower benchmarks Django and Rails are listed ahead of Laravel. A wild arbitrary goalpost appears! Even if Python is in any way comparable to PHP in ongoing execution (which I would like a lot but can't believe due to having some experience with that), we were talking about scripting, for which startup time with slim code matters, not ongoing performance with big frameworks. Cold startup time of Python is bad. Checked now for good measure: turns out PHP 7 from MacOS isn't much faster than Python either from the system or from Brew, on a “Hello world”. However on a machine with a slow CPU PHP takes the lead; and especially PHP 8 is more than three times faster than Python. This vaguely contradicts my past experience on Linux, where I was never able to make Python as fast—maybe something iffy is going on specifically on Mac. (However Perl does beat PHP by a lot, and even beats Lua on the slow machine—seems my latent hopes of using it for scripting were right, and I'll mourn its disappearance even more.)
- NorwegianDude 5y agoBenchmark on Mac(or Windows) is hard. You really have to know how it works to know what you're actually benchmarking, and if the numbers are even remotely related to what they would be on Linux. Unless the plan is to actually use in on Windows/Mac, ofc.
- phplovesong 5y agoFaster? LOL! Need speed? Use a compiled language. I rarely see a tool written in, say, python slow for what it was written for. From a user point 5ms vs 9ms in irrelevant. With PHP the speed should not be CPU related, but instead IO. PHP IO is HORRIBLE, and a default setup using framework <insert here> usually peaks around 300-600 req/sec which is almost laughable in 2021. Not that it really matters, but for CPU stuff numpy is multitudes faster than a PHP counterpart. Pypy also usually is lots faster than PHP for a given task.
- NorwegianDude 5y ago300-600 req/sec with a default setup? That seems a bit low, unless it's a very slow framework or machine. Most frameworks are slow, but not that slow. I think ~2K+ rps was what I got when I did a comparison last year. But, PHP IO is slow? What do you mean by that? A lot of things in PHP is basically just a wrapper for C, and it's really fast. I'm really interested in why you think IO is slow.
- phplovesong 5y agoThe way PHP is built (start and die) on each execution. Compared to anything else, thats "running" PHP needs to do more work on each startup. This is also why its impossible to build a websocket server in PHP (without hacks like reachphp). this is one of the main reasons PHP IO (read req/res) is slow. You can search for benchmarks if you so choose, and a basic setup for PHP is usually in the 300-600 req/sec range.