PHP versus ASP.NET – Windows versus Linux – Who’s the fastest ?

Translations of this material:

into Russian: PHP против ASP.NET. Windows против Linux. Кто самый быстрый?. Translation complete.
Submitted for translation by dzlk 06.08.2009 Published 8 years, 10 months ago.


NOTE: This is “Misfit Data” - While I do work for Microsoft, this data is NOT “official Microsoft” data and is not endorsed or ratified by Microsoft in any way. I built and ran these tests because I was personally curious about comparative performance.

If these test results cause you dizziness, vomiting, or other undesired side effects, please discontinue use immediately and consult your physician.

How does IMPLEMENTATION Performance Compare ?

Usually, when someone creates benchmarks, they are trying to prove that their thing is faster than someone else's thing.

I’m PAID by Microsoft to write BOTH PHP and ASP.NET Code. I was doing PHP before .NET shipped. I love them both.

This makes it hard for me to say anything good about either one. When I confer a preference for something in PHP, my Microsoft peers send me flame mail and when I confer a preference for something in ASP.NET, my PHP friends come out of the woodwork to call me a Microsoft shill.

I started building and running these tests because everyone had opinions about comparative PHP performance (Windows versus Linux & 5.2 versus 5.3), but no one had any solid data.

So, I decided to collect some empirical evidence of my own.

[ You can CLICK HERE to see the result spreadsheet. ]

Before you look at them, let m e provide some method details and context.

All tests were run on the SAME Machine.

A Toshiba Tecra M5 with 4 Gig of ram and a 60 Gig 7200 RPM Hard Drive.

Ubuntu 9 and Windows Server 2008 Standard were natively installed on 2 separate (but identical) hard drives.

The web servers were Apache2 on Linux and IIS 7 on Windows.

Both operating systems were fully patched / updated.

No Operating System or Development Runtime performance enhancements were added.

I wasn’t investigating how much speed an expert could custom tailor the tests to on a specific platform.

Yes, I could implement PHP Byte Caching, or for ASP.NET I could use Page Caching, Partial Page Caching, SQL Cache Dependency, Multi Threading, etc.

Both Windows and Linux Implementations of PHP will benefit from PHP Byte Code caching.

My goal was to determine the relative speed of THE IMPLEMENTATION.

I found the results both interesting and unexpected.

PHP on Linux Versus PHP on Windows.

I really though one would just be faster than the other, but I was wrong. Some things are faster on Windows, other are faster on Linux.

* RAW statement execution seems faster on Windows.

* Function Calls were faster on Windows

* Object Creation / Access was faster on Linux with PHP 5.2 but faster on Windows with 5.3

* Library calls were faster on Linux. (Example: Encryption 3-5 times faster on Ubuntu.)

* File Access is faster on Linux by a small percentage, except for file copy operations which was as much as 60% slower on Windows probably due to the ACL advanced security.

* MySQL access with Linux is faster by more than a little and on Windows, MySQL access deteriorates in version 5.3 (This seems to be poor implementation, see PostgreSQL below.)

* PostgreSQL performance is very close on both platforms (within 6/100 of a second for 1000 Operations) – It’s faster on Windows and faster still on Windows with PHP 5.3

* MS SQL Server access from PHP 5.2 on Windows is marginally slower than MySQL access on Linux. (PHP 5.3 not yet supported at the time of this writing.)

So what does all that mean ?

* We can probably say that in terms of raw execution – performance on Linux versus Windows is probably a wash (more or less equivalent) so that the performance of PHP itself becomes a moot factor in choosing Linux or Windows for PHP application deployment.

* If you are building an application, or running an application that supports it, PostgreSQL might be a better database choice since it performs pretty much the same on Windows and Linux.

* If you are running an application that locks you in to Sun Microsystems’ MySQL and you want to run it on Windows, your should do scale planning. (My personal guess is that it’s unlikely that Sun will markedly improve MySQL performance on Windows. )

* Version 1 of the PHP Driver for SQL Server (V2 is in the works) is somewhat slower than MySQL or PostpreSQL but probably not enough to discourage use where diverse developer access is desired. (v2 ot the driver will improve performance. )

By and large I think the PHP team and the Microsoft IIS team have accomplished good raw performance equivalence across platforms. (Now we just need to get the Open Source Application teams (Drupal, WordPress, Joomle, etc.) to do performance optimization on both !)

PHP versus ASP.NET Raw Performance.

By now you have cheated and looked at the spread sheet.

Yes, ASP.NET is universally faster than PHP (on Windows and on Linux) with the exceptions of File Copy and Attribute operations.

MySQL Access from PHP on Linux is a TINY bit faster than SQL Server access on Windows (assuming common data types and SELECT statements) but probably not enough to matter.

ASP.NET (C#) operations, object use, library calls, etc. are SIGNIFICANTLY faster that the PHP equivalents.

I know my PHP friends and the Linux dudes (and dude-etts) will probably come out of the wood work to refute my tests and results :)

I’ve always thought that if high end performance options were part of your needs requirements, then .NET programming has some advanced options “out of the box” like multi-threading, asynchronous requests, and a number of caching options.

NOTE – I’m not saying “ASP.NET is Faster so you shouldn't choose PHP !!!! I’ve always contended that the affable simplicity of PHP had some drawbacks for certain advanced applications. (Just as the early learning complexity of ASP.NET can have it’s drawbacks. )

To me (your mileage may vary) the exciting thing about PHP is not the language / platform so much as it is what thousands of clever PHP Developers have done with it (Drupal, Joomla, Wordpress, PHPBB, Nuke, etc.)

In any event, it’s nice to now have some data that PHP performance on Windows and Linux are “in the same ballpark”.

Now I can start writing those Windows specific PHP libraries I’ve been dreaming about for years !!


* I know some will be incensed by these tests. You are welcome to comment and disagree, but if you can be polite I’ll simply delete your comments and block your IP address.

* If you dislike the results and want to refute them – DO THE WORK. Accompany your dissent with DATA. Take my code or write your own and argue with FACTS.

Anyway – hope some of you find this interesting.

Now let the frenzy begin !!