Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19
  1. #11
    Nickson asked for a memory and CPU usage by the 2. To do so I made 2 CONSOLE application (one PHP and one C#)
    Both runs on the same machine on linux.

    PHP Source:


    C# Source:


    As you see it's the same code.

    Memory usage for C#: 88820 kB
    Memory usage for PHP: 187872 kB

    CPU usage for C#: 0m0.237s
    CPU usage for PHP: 0m13.007s

    Now the memory usage is... biased as PHP MUST load all the libraries in memory even if not used where C# loads what it needs beside the main VM.

    On the CPU side... well it's without comments...
    - Make Web Games Administrator
    - Creator of NWE
    - Owner of Nowhere Else and beyond
    - Mad developer

  2. #12
    Something I actually knew without doing a test ... but I would rather see how these test perform during a real "compatible" test. In other words, php served via apache and the output on a webpage, same with C# but then via aspx & iis . That's what I actually meant, not just a console test
    Web developer
    -----
    MakeWebGames Administrator Faq & Rules thread
    MCC Owners / Developers: please read MCC - MWG Relation

  3. #13
    And how do you judge the memory usage? CPU? Sorry I don't see well how you can do such tests...
    - Make Web Games Administrator
    - Creator of NWE
    - Owner of Nowhere Else and beyond
    - Mad developer

  4. #14
    Well I don't know, but that would really show a comparison in both their own environments. I just don't feel like this is a proper test on the same level.
    Web developer
    -----
    MakeWebGames Administrator Faq & Rules thread
    MCC Owners / Developers: please read MCC - MWG Relation

  5. #15
    Well the only thing which could be done is have a PHP script and a C# ASPx and check how many requests per seconds the server will serve... but again not really a good comparison.

    Yet for my test, the CPU speed was a good test the memory test not.
    - Make Web Games Administrator
    - Creator of NWE
    - Owner of Nowhere Else and beyond
    - Mad developer

  6. #16
    My only criticism of your overview is that it many of these items are not a comparison of C# to PHP, but rather the Web Forms framework to PHP. While WF does automate quite a bit of code generation, it often comes at a price in terms of speed, cleanliness, and request / response sizes (due to view and control states which can become quite large). .NET's modular composition allows almost of all that to be remedied by overriding base system objects, so it's not necessarily a deficiency - and if it were, it would be with WF and not C# itself.

  7. #17
    True I compared the ASP.NET framework (Web Forms) to PHP and not plain C#, but as said I want to compare what offers ASP.NET natively with what offers PHP natively.

    It is true that ASP.NET includes a few things like the viewstate which is nothing else than the serialization of the properties of the controls which tends to be big, but in most cases it will not harm. Also if you don't want you can as well code without all those and just generate plain HTML out of your C# code.
    - Make Web Games Administrator
    - Creator of NWE
    - Owner of Nowhere Else and beyond
    - Mad developer

  8. #18
    Another item of interest on the subject of ASP.NET would be the new-ish MVC framework which is distributed with .NET 3.x and 4.x. While you lose the ease of drag-and-drop development and the event driven nature of the Web Forms framework, it more than makes up for it with automated tests and clean code separation.

  9. #19
    Quote Originally Posted by a_bertrand View Post
    Some of you may think C# / ASP.NET is yet just another way to develop web pages or do not even know that C# allows to develop web pages. With this little post I want to show some of the main differences between PHP and C# web development.

    PHP Logic:
    PHP generates directly the HTML / JS / CSS used to compose the page and produce the end HTML page directly from the code or if you are smart enough using things like templates engines. You must know HTML at least to be able to develop PHP web sites.

    C# Logic:
    You compose your page out of "web components" which are aware of their state and can fire events like "button click". Once a event is fired, your C# logic (no HTML / JS here) will change the state of the page components or add new one on the fly. Components are then invoked by the framework to render themselves. You don't have to know anything to HTML to be able to code.

    A PHP register form:
    You generate the HTML for the form, then somebody press the submit which call the same or another PHP file, the new file check the form data and either call again the first page (with hopefully some sort of errors) if it doesn't work, or save the data and goes on. In most cases the form data are lost if there is an error as it's annoying to put back the submitted data to the form and developers are lazy.

    A C# register form:
    Beside there is a pre-made register / login form, you could use the standard textbox, labels C# offers you. Then an ASPx button will be used to submit the form. On the event of the button click you check if all is fine, if not you simply show some text in a label, and all the form fields will keep their data without any work on your side. If all is fine, you save the data in the DB and redirect to a new page.

    PHP templates
    By default PHP doesn't make any separation between the look and the logic. So either you use additional packages or write yourself some sort of template engine. If not then you will have an hard time to change the look (beside changing CSS files).

    C# templates
    The logic code is separated from the presentation code. The presentation code is nearly a pure HTML code with some additional tags for the controls. The logic on the other side is a pure cs file (C# file) and is compiled to produce a .dll file.

    PHP software distribution
    When you give away a soft written in PHP you normally give out your sources as nothing is compiled. To avoid that you must use some special software to encrypt your code, and those soft are not free nor really safe.

    C# software distribution
    As the logic is normally compiled you can safely distribute your software. Yet of course there is some softs to de-compile C# code, in case you want to be safe also against that, you can also use some obfuscation software (not really expensive).

    PHP performances
    PHP is an interpreted language. Sure you can use some accelerators but still it remains a slow interpreted language. For most web pages it is fine, but as soon as you want to produce images on the fly or yet do some more complex operations PHP will start to use a lot of CPU and time.

    C# performances
    Performances varies between Linux and Windows machines. On Linux the performances are still like 10x the one of a PHP equivalent, but not yet really fast. On windows C# is nearly as fast as pure C++ code.

    Background tasks on PHP
    Basically impossible to handle... As soon as the web page is shown your program dies.

    Background tasks on C#
    You can have as many background threads and even keep things in memory. Threads will continue to run in background even after a page is loaded. You can cache things in memory for example from a database or you can even communicate between different web sessions for example to create a chat (all that is not directly possible in PHP).

    PHP Ajax
    PHP doesn't have any native support for AJAX. Either you code it yourself or try to find some library which help you.

    C# Ajax
    C# does have a full AJAX support. Which means you can have events which call back the server without reloading the page, you can have timers to pool data at regular interval and much more. You can even design AJAX aware components but any web components can be updated without any page reload.

    PHP minimal tools
    A web server with PHP support and some text editor.

    C# minimal tools
    A web server with ASPx support (apache with mod_mono or IIS), some text editor, and a C# compiler. However you can download and use MonoDevelop (free and open source) or use Visual Studio (much better but beside a free Express Edition it costs).

    Debugging a PHP application
    Quick answer: a nightmare. You need to put echo every 2 lines or if you are really skilled you can try some PHP debugger (which honestly I always failed to use correctly).

    Debugging a C# application
    Easy: inside Visual Studio (as well as MonoDevelop) you have a full debugger at your fingers. You can put breakpoints, let your soft run, and see how it goes with the variable and you may even change the value of a variable on the fly or move the "running step" where you want.

    When would I use PHP
    I would use PHP if I want a minimal Linux installation and yet do not develop too complex websites. Or if I need to be hosted on some host providers which doesn't offer any alternative for ASPx

    When would I use C#
    I would use C# for all web development which involve more than some simple dynamic web page. Visual Studio makes me gain a lot of time and the framework is really powerful.
    Wow, really good and helpful! Thanks!

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •