So many times I have heard php pushers claim that php is so much faster than Asp.Net and that Asp.Net is clunky and slow.
The most annoying part is that everything I have read (that is not factless opinion), and I mean everything
, says that this is wrong; but for some reason, this myth is widely accepted.
It has become a religious argument that ignores the facts.
Instead of arguing this point over and over, I decided to put it here so I can simply refer people to it to set them straight.
Keep in mind that I wrote strictly php for over 4 years, it is a great and powerful language that I have nothing against.
Not to mention you should not choose your development language by speed, but by what works for you (more on that later).
This post is not there to pick sides (though I am now Asp.Net biased of course), just to show the facts.
compiled vs interpreted languages
First of all, at the very base of the argument it has to be realized that the two languages are very different.
Asp.Net is an optimized and compiled language, meaning code you enter is reduced to a set of machine-specific instructions before being saved as an executable file.
Even if you do not explicitly compile your code before you deploy it, it compiles the first time it is run, then after that it runs as compiled code.
Php on the other hand is an interpreted language, meaning it is saved as the code your write and run directly from that code.
It is widely accepted and proved many times over that Compiled programs generally run faster than interpreted ones because interpreted programs must be reduced to machine instructions at runtime
Here is a quote from Wikipedia that shows just how much faster they can be:
"A program translated by a compiler tends to be much faster than an interpreter executing the same program: even a 10:1 ratio is not uncommon. The mixed solution's efficiency is typically somewhere in between."
Now that the theory of why it is faster is out of the way, let's get to some cold hard numbers, so we can put this debate to rest.
The following charts and benchmarks are taken from WrenSoft
and quite simply show the difference.
Please follow the link if you want an in-depth description of the test.
This first graph shows the time taken to generate and display results for a search a small website.
As you can see, the average time for the php site: 0.1500 seconds, the time for Asp.Net: 0.0150 seconds... that is a HUGE difference, the php search takes 10 times as long!
The next one does the same with a larger site, and the results are not much different.
Php took an average of 1.0097 seconds while the Asp.Net run took 0.0810 seconds; php took more than 12 times as long to run, the numbers are there.
Now those tests were run with basically the same code translated into different languages, so there isn't much ammunition in the 'it was coded poorly' argument.
But, there is still the [valid] argument that the above tests were run on a Windows machine, and since .Net is native to Windows, it was an unfair trial, so now we will look into the statistics running on Linux, so php will have the 'home-field' advantage; not to mention, c# will be running on Mono.
These benchmarks are taken from shootout.alioth.debian.org
who has numerous benchmarks for all sorts of languages and is a fantastic resource.
For these tests, I am choosing to compare both vs the baseline of 'Clean' so it is easier to compare; here are the results:
As you can see, even on Linux, .Net is faster across the board; often many times faster.
The only other tests I can think would be interesting to run is to compare scalability and such; I would be very interested if anyone has benchmarks for such things.
can we finally focus on what matters?
Go ahead and google asp.net vs php speed
and you will see that almost all of the posts scream that php is faster, but you will not find any links or evidence backing this up.
The whole point of this for me is not even really to show that that Asp.Net is faster, I already knew that; it is to possibly help curb the ridiculous assertions that it is faster.
It has basically turned into a religious argument, not a fact based one and that is just silly to me.
As in many other things, it seems as if enough people yell something long and hard enough, it becomes 'truth' - it simply is not.
Developing in php is fine, a huge number of amazing applications and websites are written in it by much more skilled coders than myself.
That said, you shouldn't choose your language on speed, as development preference is much more important; use php if you feel it is a superior language, but don't push bad information. Most importantly focus on what matters: code in what language you can do your best work in
, you don't need to justify it to anyone else, prove that it is faster/better or convert anyone else to using you language - you have better things to do.
But... Asp.Net is faster than php. Period.