views:

3769

answers:

10

Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.

I enjoy using pylons and I would still use it if it was slower than php. But if pylons was faster than php, I could maybe, hopefully, eventually convince my employer to allow me to convert the site over to pylons.

A: 

If it ain't broke don't fix it.

Just write a quick test, but bear in mind that each language will be faster with certain functions then the other.

Unkwntech
A: 

The only right answer is "It depends". There's a lot of variables that can affect the performance, and you can optimize many things in either situation.

Aeon
A: 

Check out the programming languages shootout:

http://dada.perl.it/shootout/

Doug T.
That benchmark seems a little outdated since it only uses PHP 4 which is significantly different from PHP 5 in most ways, including performance.
Techpriester
Jimmy
+1  A: 

You need to be able to make a business case for switching, not just that "it's faster". If a site built on technology B costs 20% more in developer time for maintenance over a set period (say, 3 years), it would likely be cheaper to add another webserver to the system running technology A to bridge the performance gap.

Just saying "we should switch to technology B because technology B is faster!" doesn't really work.

Since Python is far less ubiquitous than PHP, I wouldn't be surprised if hosting, developer, and other maintenance costs for it (long term) would have it fit this scenario.

Peter Bailey
A: 

It's about the same. The difference shouldn't be large enough to be the reason to pick one or the other. Don't try to compare them by writing your own tiny benchmarks (hello world) because you will probably not results that are representative of a real web site generating a more complex page.

indentation
+1  A: 

PHP and Python are similiar enough to not warrent any kind of switching.

Any performance improvement you might get from switching from one language to another would be vastly outgunned by simply not spending the money on converting the code (you don't code for free right?) and just buy more hardware.

SCdF
+8  A: 

There's no point in attempting to convince your employer to port from PHP to Python, especially not for an existing system, which is what I think you implied in your question.

The reason for this is that you already have a (presumably) working system, with an existing investment of time and effort (and experience). To discard this in favour of a trivial performance gain (not that I'm claiming there would be one) would be foolish, and no manager worth his salt ought to endorse it.

It may also create a problem with maintainability, depending on who else has to work with the system, and their experience with Python.

Rob
+19  A: 

It sounds like you don't want to compare the two languages, but that you want to compare two web systems.

This is tricky, because there are many variables involved.

For example, Python web applications can take advantage of mod_wsgi to talk to web servers, which is faster than any of the typical ways that PHP talks to web servers (even mod_php ends up being slower if you're using Apache, because Apache can only use the Prefork MPM with mod_php rather than multi-threaded MPM like Worker).

There is also the issue of code compilation. As you know, Python is compiled just-in-time to byte code (.pyc files) when a file is run each time the file changes. Therefore, after the first run of a Python file, the compilation step is skipped and the Python interpreter simply fetches the precompiled .pyc file. Because of this, one could argue that Python has a native advantage over PHP. However, optimizers and caching systems can be installed for PHP websites (my favorite is eAccelerator) to much the same effect.

In general, enough tools exist such that one can pretty much do everything that the other can do. Of course, as others have mentioned, there's more than just speed involved in the business case to switch languages. We have an app written in oCaml at my current employer, which turned out to be a mistake because the original author left the company and nobody else wants to touch it. Similarly, the PHP-web community is much larger than the Python-web community; VPS hosts are more likely to offer PHP support than Python support; etc.

But back to speed. You must recognize that the question of speed here involves many moving parts. Fortunately, many of these parts can be independently optimized, affording you various avenues to seek performance gains.

Ross
The benefit of compiled .pyc byte code files in Python is overrated when using something like Apache/mod_wsgi. This is because they only come into play at time module is first loaded. After that it is all cached in memory between requests. Byte code caching systems are a bigger deal for PHP because the application is effectively thrown away after every request and so it has to reload code for every request.
Graham Dumpleton
A: 

an IS organization would not ponder this unless availability was becoming an issue.

if so the case, look into replication, load balancing and lots of ram.

+1  A: 

I had to come back to web development at my new job, and, if not Pylons/Python, maybe I would have chosen to live in jungle instead :) In my subjective opinion, PHP is for kindergarten, I did it in my 3rd year of uni and, I believe, many self-respecting (or over-estimating) software engineers will not want to be bothered with PHP code.

Why my employers agreed? We (the team) just switched to Python, and they did not have much to say. The website still is and will be PHP, but we are developing other applications, including web, in Python. Advantages of Pylons? You can integrate your python libraries into the web app, and that is, imho, a huge advantage.

As for performance, we are still having troubles.

notageek