Asp.Net vs php : speed comparison

why is the myth that php is faster than Asp.Net so prevalent? Asp.Net is faster than php, here are the facts

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

the numbers

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

Shout it kick it on

Comments (39) -

  • > I am choosing to compare both vs the baseline of 'Clean' so it is easier to compare...

    Just compare them directly one against the other!

    > As you can see, even on Linux, .Net is faster across the board...

    That's performance on command-line apps without caching - not ASP.Net versus PHP web apps!

    "Overall Performance: PHP is rarely the bottleneck"
  • @Isaac,
      You can go ahead and compare them versus one another on the site if you want to.  I just feel it is much easier to compare graphical representations vs a control than it is to an unknown data point - much easier to compare.  Aslo, I understand what the test is, but it is not misleading, as this is what in essence runs the web apps.
  • The opinion you've come across is probably a bit of a hold over from the days of the old classic ASP which was terribly slow (as shown by your own graphs).

    I'd say that C#/ASP.NET should perform slightly better than PHP, due to their different natures and designs. Mainly the fact that one is compiled and the other interpreted.

    However, I think your comparison is a bit unrealistic since it is rare to find PHP being used in a performance sensitive situation without an opcode cache in place to mitigate the interpretation time.

    That more realistic would be more interesting to me, though I doubt it will ever represent a concern for real world usage since in a real world stack 60% or more of the time is spent after the server response and within the server side processing time it is mostly external dependencies such as database access.
  • I've never heard anyone say that PHP is faster than C#/Compiled languages.... that's just... bonkers...
  • If you are talking about raw number crunching, then of course, c# is going to destroy php in performance. If you are talking about client experience, by its nature is going to slow things down tremendously.

    First of all, the markup it renders is as bad as you can get while remaining valid html. Php doesn't have controls, so the quality of the markup is dependant on the developers skill. Since gives about the worst possible result, chances are a php site will have cleaner html, which results in much faster page rendering.

    Secondly, serializes all of its state info to a hidden field. As soon as someone drops a gridview on a page, it would take a spectacularily poor php developer to come up with something that would take a longer time to push back and forth over the wire.

    Thirdly, javascript libraries are notoriously verbose and poor quality. A php developer will most likely be using prototype or jquery, both of which are miles better then ajax.

    Lastly, the quality of controls has fallen so far behind freely available javascript widgets it is sad. An site typically looks like something made a decade or so ago just due to this fact.

    Now you may say, a good developer can just chuck all those things out the window and use the same tools available to a php developer if he so wishes. While this is true, doing this is often very ugly from a code point of view, and is frequently quite difficult due to how the framework gets in your way.

    All of these things mean that makes it harder to create a good user experience then pretty much any platform, php included (note: I friggin hate php). While you are totally correct that in raw performance, .net is a phenomenal platform, raw performance is not anywhere near as important for a web application then a great many other concerns. This is why you rarely see applications outside of corporate intranets (unless microsoft pays someone to use it).
  • Matt, I understand what you are saying and they sound like solid points - the control markup is less than desirable and many .netters I know avoid the nasty ones at all costs.Do you have any data showing this?  It would be interesting to see how much of a difference it makes. You are making valid points, but without any numbers, it appears as opinion on what you think would be the case (could easily be correct, but just as easily be false).

    Also, I have to disagree that it is rare to see applications 'in the wild', some huge, high traffic sites are written in StackOverflow, Amazon, etc.
  • @ naspinski I just feel it is much easier to compare graphical representations vs a control than it is to an unknown data point - much easier to compare.

    C# versus Clean shows 5 Clean programs are faster than C#.

    PHP versus Clean shows 1 Clean program faster than C#.

    We can't tell if those are the same programs from the charts.

    From the charts, how many PHP programs were faster than C# programs?
  • As soon as a browser finds a <table> tag, it will stop rendering until it finds the matching </table> tag. If your entire page is in nested tables, you are going to experience a slowdown in rendering just because the browser has to wait to receive everything before it can even start displaying the page. Divs do not have this problem. The other issue is that tables can get quite verbose, which increases the size of the html file. There is also a computational hit, but in todays day and age, that is a non issue. I do not have any numbers, but based on personal experience as a web developer of 7 years, tables will slow your page down.

    StackOverflow uses MVC, which addresses many of the issues I brought up. MVC is currently being pushed as the "alternative framework" for people who "want more control" by Microsoft.

    Amazon doesn't use MySpace does, but microsoft paid them to. is the other big public site that uses, but it is basically just doing a bunch of response.writes, not using controls. The vast majority of significant public sites out there are either php or rails.
  • You should also note that PHP running on IIS 7 is the fastest PHP web server because IIS 7 makes it multithreaded. Smile
  • @Matt,
      I concede that most sites are written in php.  I also agree with what you say about tables, that is pretty well known, but I don't understand the connection.  There are controls that make tables such as GridView, DetailsView, etc.  But there are also many that don't, and options for all of the (GridView, DetailsView, etc) to be css friendly and use divs with no tables at all.  Also, I don't know where the argument of large amounts of nested tables come in?  But really, I feel it beside the point of what I am trying to convey.

    I have also been writing code for about 9-10 years now, 4 of those in php, and I feel that truly speed comes down to the developer, and not the language as you are illustrating with your comments.

    I do not want to make this a language war, it is simply showing the raw numbers of speed of a language [in ideal conditions] - we can argue syntax, implementation, etc all day and be right back where we started.
  • Great comments by the way!  Thank you all
  • ASP.NET is not a language.

    C# will run faster than PHP, no-one is going to disagree with that. But ASP.NET implies clunky web controls, nasty viewstate, etc.

    I think it is fair to say that most websites that use ASP.NET are "slower" than their PHP equivalents, not because they execute slower on the server, but because of the fluff that the client has to send and receive.

    ASP.NET MVC, on the other hand, is another story...

    Where did you get the idea that Amazon uses ASP.NET!?

  • @Hainesy,
      Once again, clunky web controls, viewstate, etc are all optional - but I don't want to do this debate as I stated multiple times in my post as well as comments - that is not the point of the post!

    -I have no idea why I though amazon used, my mistake Tong - it's the end of my 180th consecutive 12 hour work-day, cut me some slack Smile
  • @napinski

    The difference is between default output and the sort of changes that does. Tables are an extreme example, but most control output, while valid, is not what most people consider up to the standards of modern web development.

    What my point was is that raw computational efficiency is a fairly unimportant metric in web development. Things need to be "fast enough", anything beyond that is mostly irrelevant. One that is far more important is how easy it is to deliver a good user experience, and with the framework is actually working against you.

    When people say php is fast and is slow, they are not talking about number crunching. What they are talking about is the meg and a half html file that is being pushed over the wire on every postback (due to viewstate), or the 500k AJAX requests when updating 2 characters of text.
  • @naspinski You probably meant or Those sites are developed entirely on .NET stack.

    Good article.
  • As others have mentioned previously, MVC != WebForms...But I guess they're both "ASP.NET"  This article seems like it's a comparison between PHP and WebForms.  Hainsey and Matt's arguments seem geared at the WebForms world and I'm not debating the Viewstate, messy HTML, etc. arguments.  That all said, it doesn't seem like those arguments apply to MVC...

    SO...if you are comparing MVC to PHP...who wins?  E.g., what are the arguments against MVC?
  • Indeed, as I stated "...they're both ASP.NET"  My question still applies, though.  If the comparison is PHP vs. WebForms = the viewstate/messy HTML/etc arguments are arguably arguments that count against WebForms.  If the comparison is PHP vs. .NET MVC...what are the cons for ASP.NET?
  • This is fantastic, I have been tasked with a comparison similar to this at work, it is nice to have some actual research behind your post.
  • Plenty of us are developing fast, clean WebForms applications.  It's a mistake to assume that anyone using ASP.NET is relying heavily on poorly rendering controls, not minding the quality of their markup, and not controlling their ViewState.  Those assumptions are as faulty as assuming that only hobbyists use PHP and that none of them understand object orientation.

    Similarly, it's completely incorrect to assume that our choice of server-side frameworks somehow precludes a particular client-side framework.  Especially in light of jQuery being officially adopted and supported by Microsoft this year.

    A couple more large ASP.NET based sites for the list:,
  • @Hainesy: The viewstate may be an issue if you don't know what you are doing. It is usually turned off in most cases. And as Naspinski says, Webforms offer various levels of control over HTML. It is very easy to get Webforms output raw "full control" Html when needed.

    @SanjayU: None Smile
  • @Matt
    "Now you may say, a good developer can just chuck all those things out the window and use the same tools available to a php developer if he so wishes. While this is true, doing this is often very ugly from a code point of view, and is frequently quite difficult due to how the framework gets in your way."

    I'm not sure how one language can be "uglier" when the two languages with similar constructs are used in the same way.

    Ifs are ifs, whiles are whiles, what specific "ugly" raw and php ish code are you talking about?

    <?php= myClass->getSomething() ?>


    <%= myClass.getSomething() %>

    Look pretty similar to me.  There are only so many ways you can loop through sql results and display them in a grid.
  • I would like to see your benchmarks with xcache or apc enabled on php.  Typically you can see over a 100-200% improvement in speed. Running op code caching is standard vanilla for most production servers but it's totally omitted from this post.  Obviously compiled apps are faster than interpreted.  But look at python, it creates compiled versions of interpreted files (.pyc) so the next time you run its near native C speeds.  Op code caching is the same idea for PHP. Both python and php are written in C

    I also think the test used to "prove" ASP is faster than the php isn't very string as it only tested one application.   Interesting article though.

    Please take a look at
  • @John

    I am talking about tossing the bad aspects of The framework makes it difficult to use client side tools to replace those bits compared to other platforms. ctrl00_blah_blah_blah is one interesting thing, another is the non standard date json serialization, another is the inflexibility of event validation, another is how complected writing or extending non trivial controls can be, etc, etc.

    I my comment ended up trolling a lot more then I intended, and I am sorry for that. Again, what I was trying to say is that raw performance is a metric that doesn't matter much, if the user experience is slow people are going to say the platform is slow. Another is example of this is java; the platform has arguably the fastest runtime out there, however the gui toolkit is sluggish and unresponsive. Because of that, people think java is slow. You can put out benchmarks that show how it actually outperforms c++ in some scenarios, but that is completely irrelevant if you are talking about it in the context of an app with a sluggish UI.
  • @MattBriggs

    ASP.NET webforms 4 solves a lot of problems with dirty markup, you can now specify a client ID [you can do this in ASP.NET 2+ by inheriting from the web control and overriding the ClientID property, but then if you ever have two controls with the same name (one on a web form and one in a user control for example] you'll get errors on postback) and have the client id nicely incremented in a repeater so it remains unique but human readbale. Will make coding with JQuery a lot easier.

    But yeah ASP.NET vs PHP, well both depend on how much the developer cares about performance. Anyone can make  adog slow site. ASP.NET's automatic caching (<outputcache>) and ability to use MasterPages, UserControls and ServerControls is a nice way of doing things, reusable, OO code.
  • uses it has a routed handler though that lets the URLS be nicer (or a lot of Default.aspx files, but I doubt it) however I don't think it's MVC because the viewstate clip is still gigantic.
  • Great post! But ASP.NET code isn't compiled into the machine code, in fact it gets compiled into some kind of the byte code. Anyway, it's still a lot faster than interpreted PHP code.
  • I prefer PHP to ASP.NET
  • Sure php has no controls, but .net is not forcing anyone to use viewstate, sessionstate, built in controls or MS.Ajax either.

    Make believe they dont exist and use jquery, json, ajax, literals, maybe some placehoders or custom controls if really needed, or set a simple htmlcontrol to runat server.

    ..all depends if you juste like to drag & drop code because you have a ton of controls sitting convieniently in your toolbox, or don't mind getting into the nitty gritty html/css/js stuff that most php developers are forced to do anyways, but while still profiting from the .net framework like: the IDE, debugging, compiled code, IIS7, all the built in goodies of the different assemblies of framework,  ..and probably running fast too.

    Monster.con was a pretty bad example even if it is a big site: viewstate, loads of controls, not to mention tons of inline javascript dispersed throughout the whole page.
  • I won't even start to mention all the nice stuff like extension methods, generics, linq, providers, localisation, caching, and how easy it is to create & deploy sites in IIS7 is, and use things like application request routing, url rewrite, dynamic ip restrictions ...and whatnot.

    Enough bashing ..sorry. But after 4 years of php and 5 years of .net, i know which one i prefer Smile
  • SC
    Saving a fraction of a second in processing may not be of significance when the overall round trip is what matters for the end user. The bench-mark to consider is the time needed from submission of a request to rendering a page. There are so many other variables involved (bandwidth,file size, database,processing speed etc). Would the difference in processing speed be insignificant when compared to the round trip? Also how do thing compare under heavy load, say 100 people making the same request simultaneously?
  • Michael made a post above about opcode caching. This is very important: When using opcode caching, PHP works like a compiled language (not native but rather executed by a virtual machine).

    The speed differences seen when opcode caching is employed will change the appearance of the graphs significantly.
  • Do any of your comparisons include the idea of a PHP accelerator?  Here is some info:  There also have been many other advancements that put PHP above most other interpreted languages so if you are grouping PHP in with all other interpreted languages then you would be mistaking.  I am not going to say that PHP is faster than C# because that would be retarded but the developers of the PHP project think much differently than the Microsoft developers.  As we all know, speed and performance are not always considered when Microsoft puts out a new release of anything, on the other hand it is always considered on the PHP end.
  • interesting debate... not to forget the development time! i am daily shocked how long it takes my team to make minor (interface/usability flow) changes that would be possible in 5 minutes with PHP. (i write PHP myself).
    those clunky components are not just painful to style, it is also nearly impossible to make usability changes
    e.g positioning a field from one component like a dropdown box in the <div> area of a grid, without recreating the CSS for a third component that they have to use to make it happen... IF they find one that can do the trick.

    also the compiling time until you finally get to see the result of your code change.

    to me feels slower, not just the result, also the development process... i would say it takes about double as long to write a web app or content management system. those "handy" components slow everything down.

    pro PHP!
  • It comes from my personal experience when working with two major websites in PHP which the client wanted to convert to .NET. After the conversion, we compared the load tests and realized that there is a slight reduction in hosting costs because of the inbuilt support in for session scaling like State server and sql server based sessions.PHP does scale, but I guess there is no in built support like in ASP.NET, hence the term "costly".Thanks for the update.
  • I m using PHP from last 4 years and in my opinion PHP is the best language for the website, though got alot of other advantages, but according to me php codes are more flexible and uncomplicated. on other hand works perfectly but from designing side of view I struggle some times to make things right.
  • What was the PHP setup?!?

    Try mod_php under Apache with APC! NOBODY uses PHP in production without an op-code accelerator (which caches the compiled op-code and executes it from memory).

    Do you really think Yahoo! and half the web's most popular websites have their servers constantly re-parsing & compiling the same code hundreds of times a second?!?

    Luckily, PHP6 has op-code caching/accelerator enabled by default.. so clueless people, who don't know how to set up a server, will see real performance when they run their silly little "benchmarks" on the default (dev environment) setup !
  • Only .NET . . . .

Pingbacks and trackbacks (31)+

Comments are closed