views:

2283

answers:

9

I have a friendly argument going on with a co-worker about this, and my personal opinion is that a ASP.NET-MVC compiled web application would run more efficiently/faster than the same project that would be written in PHP. My friend disagrees.

Unfortunately I do not have any solid data that I can use to back up my argument. (neither does he)

To this, I tried to Google for answers to try and find evidence to prove him wrong but most of the time the debate turned into which platform it is better to develop on, cost, security features, etc... For the sake of this argument I really don't care about any of that.

I would like to know what stack overflow community thinks about the raw speed/efficency of websites in general that are developed in ASP.NET with MVC versus exactly the same website developed with PHP?

Does anyone have any practical examples in real-world scenarios comparing the performance of the two technologies?

(I realize for some of you this may very well be an irrelevant and maybe stupid argument, but it is an argument, and I would still like to hear the answers of the fine people here at S.O.)

+15  A: 

It's a hard comparison to make because differences in the respective stacks mean you end up doing the same thing differently and if you do them the same for the purpose of comparison it's not a very realistic test.

PHP, which I like, is in its most basic form loaded with every request, interpreted and then discarded. It is very much like CGI in this respect (which is no surprise considering it is roughly 15 years old).

Now over the years various optimisations have been made to improve the performance, most notably opcode caching with APC, for example (so much so that APC will be a standard part of PHP 6 and not an optional module like it is now).

But still PHP scripts are basically transient. Session information is (normally) file based and mutually exclusive (session_start() blocks other scripts accessing the same user session until session_commit() or the script finishes) whereas that's not the case in ASP.NET. Aside from session data, it's fairly easy (and normal) to have objects that live within the application context in ASP.NET (or Java for that matter, which ASP.NET is much more similar to).

This is a key difference. For example, database access in PHP (using mysql, mysqli, PDO, etc) is transient (persistent connnections notwithstanding) whereas .Net/Java will nearly always use persistent connection pools and build on top of this to create ORM framewroks and the like, the caches for which are beyond any particular request.

As a bytecode interpreted platform, ASP.NET is theoretically faster but the limits to what PHP can do are so high as to be irrelevant for most people. 4 of the top 20 visited sites on the internet are PHP for example. Speed of development, robustness, cost of running the environment, etc tend to be far more important when yous tart to scale than any theoretical speed difference.

Bear in mind that .Net has primitive types, type safety and these sorts of things that will make code faster than PHP can run it. If you want to do a somewhat unfair test, sort an array of one million random 64 bit ints in both platforms. ASP.NET will kill it because they are primitive types and simple array swill be more efficient than PHP's associative arrays (and all arrays in PHP are associative ultimately). Plus PHP on a 32 bit OS won't have a native 64 bit integer so will suffer hugely for that.

It should also be pointed out that ASP.NET is precompiled whereas PHP is interpreted on-the-fly (excluding opcode caching), which can make a difference but the flexibility of PHP in this regard is a good thing. Being able to deploy a script without bouncing your server is great. Just drop it in and it works. Brilliant. But it is less performant ultimately.

Ultimately though I think you're arguing what's really an irrelevant detail.

cletus
"As a bytecode interpreted platform, ASP.NET" - there is no interpretation for Java or .NET whatsoever. There is a 2-stage compilation : 1-source code to bytecode / IL, 2-bytecode/IL to native code. In the end only native code is executed.
Andrei Rinea
Excellent and insightful comparison. But I have to point out one thing "...flexibility of PHP in this regard is a good thing. Being able to deploy a script without bouncing your server is great." You certainly do NOT need to bounce your server in ASP.NET to release code changes.
Tion
@Tion I'm less familiar with ASP.NET hot deploys than some other frameworks but in Java for example you can drop in JSP files and *sometimes* can reload classes but in a lot of cases you simply need to restart. How does that compare?
cletus
+2  A: 

In my (non-hardbenchmarked) experience Asp.Net can certainly compete (and in some areas surpass) PHP in terms of raw speed. But similar with a lot of other language-choice related questions the following statement is (in this case) valid (in my opinion):

  • There are slow, buggy sites in language x (be it PHP or Asp.Net)
  • There are great, fast sites in language x (be it PHP or Asp.Net)

What i'm trying to say: the (talents of the) developer will influence the overall speed more than a choice between two (roughly equivalent in some abstracted extent) technologies.

Really, an 'overall speed' comparison does not make a lot of sense as both can catch up to each other in some way or another unless you're in a very specific specialist niche (which you have not informed us about).

ChristopheD
+1  A: 

I'd tend to agree with you (that ASP.NET MVC is faster), but why not make a friendly wager with your friend and share the results? Create a really simple DYNAMIC page, derived from a MySQL database, and load the page many times.

For example, create a table with 1,000,000 rows containing a sequential primary key, and then a random # in the second column. Each of your sites can accept the primary key in a GET, retrieve the random # based on the passed in key, and display the random # in some type of dynamically generated html.

I'd love to know the results ... and if you have a blog or similar, the rest of the world would too (this question gets asked ALL the time).

It would be even better if you could build this simple little app in regular ASP too. Heck, I'd even pay you for these results if the test was well designed. Seriously - just express your interest here and I'll send you my e-mail.

Jess
That's a really cool idea. I just might try that.
Roberto Sebestyen
+1  A: 

Generally ASP.Net will perform better on a given hardware than PHP. ASP.Net MVC can do better still (can being the operative word here). Most of the platform is designed with enterprise development in mind. Testable code, separation of concerns etc. A lot of the bloat in ASP.Net comes from the object stack within the page (nested controls). Pre-compiling makes this better performant, but it can be a key issue. MVC tends to allow for less nesting, using the webforms based view engine (others are available).

Where the biggest slowdowns in web applications happen tends to be remote services, especially database persistence. PHP is programmed without the benefit of connection pooling, or in-memory session state. This can be overcome with memcached and other, more performant service layers (also available to .Net).

It really comes down to the specifics of a site/application. this site happens to run MVC on fairly modest hardware quite well. A similar site under PHP would likely fall under its own weight. Other things to consider. IIS vs. Apache vs LightHTTPD etc. Honestly the php vs asp.net is much more than raw performance differences. PHP doesnt lend itself well to large, complex applications nearly so much as asp.net mvc, it's that simple... This itself has more to do with VS+SCC than anything else.

Tracker1
A: 

A lot of it for me is wrapping my head around the programming style of usoft based software. In college, I had NO problem reading and writing my OOP stuff. Of course, digging into the STL took LOTS of coffee and late night sessions. I can say I can use it, and understand what it achieves, but all the details, no.

OTOH, there never seems to be any logical flow the the naming and design of usoft API elements. I always feel like that aspect of usoft is always FUD, market-speak and not for people who want to seriously understand what they're using.

I just settled on Symfony PHP MVC for a project after going through a few of them. For the same reason, it's documentation came from this aspect, "The web app generally has blah, blah environment, blah blah assets and will need a way to integrate them with logical sturcture. Here is what we did to allow and enforce it. These are the reasons why for each of the elements. These naming conventions signal that each of these elements belongs to blah blah part of the structure."

I have NEVER seen documentation from usoft like that. (Of course, Oracle is even worse, that's why I use Postgres, not because of the price difference.) They NEVER admit that they are solving a problem in a similar way that the college books and conference papers have been calling for or use standard computer problem space naming for solutions. NIH, (Not Invented Here) naming or descriptions are avoided.

But, there are people, LOTS of people who have learned One Microsoft Way. And they build as much beautiful or crappy stuff as anybody else. So, let's all use what we're comfortable with :-)

Dennis
Can I ask what you are talking about? I don't understand how you are answering my question?
Roberto Sebestyen
+2  A: 

maybe this could be interesting for the present thread.

pomarc
Thanks I was looking for something like this.
Roberto Sebestyen
A: 

Without any optimizations, a .net compiled app would of course run "faster" than php. But you are correct that it's a stupid and irrelevant argument because it has no bearing on the real world beyond bragging rights.

pbreitenbach
A: 

Thanks a lot cletus. That's a really impressive analysis.

+1  A: 

Need to note that question is .NET MVC vs PHP, not .NET (Web Forms) vs PHP. I don't have the facts, but general feeling is PHP websites run faster than .NET Web form sites (and I do .NET only). .NET web forms despite being compiled vs interpreted PHP is generally slow because all the chunk of code that is autogenerated by the .NET engine to render the HTML for each < asp:control > you use on design mode. Getting a .NET web form to compete in speed with PHP is a complete odisea that starts with setting EnableViewState = false, and can end on using every html control with runat=server... crazy uh?

Now, MVC is a different story, I had made two websites using .NET MVC2 and feeling is good, you can feel the speed now! and code is as clean as any PHP website. So, now, MVC allows you write clean code as PHP does, and MVC is compiled against PHP interpreted, it can only lead to one thing, MVC faster than PHP... time will prove, when the general sense is "MVC websites runs faster than PHP" then we will be right about what I say here today.

see/you/!

Nestor