Programing

코드 실행 속도 : ASP.NET-MVC 대 PHP

lottogame 2020. 11. 4. 07:38
반응형

코드 실행 속도 : ASP.NET-MVC 대 PHP


나는 이것에 대해 동료와 친근한 논쟁을 벌이고 있으며, 개인적인 의견은 ASP.NET-MVC 컴파일 된 웹 애플리케이션이 PHP로 작성된 동일한 프로젝트보다 더 효율적이고 빠르게 실행된다는 것입니다. 내 친구는 동의하지 않습니다.

불행히도 저는 제 주장을 뒷받침하는 데 사용할 수있는 확실한 데이터가 없습니다. (그도 마찬가지)

이를 위해 나는 구글에 답을 구해 그가 틀렸다는 증거를 찾으려고 노력했지만 대부분의 시간 동안 토론은 개발하는 것이 더 좋은 플랫폼, 비용, 보안 기능 등으로 바뀌 었습니다. 나는 그것에 대해 전혀 신경 쓰지 않는다.

MVC를 사용하여 ASP.NET에서 개발 된 웹 사이트의 원시 속도 / 효율성에 대해 스택 오버플로 커뮤니티가 생각하는 것과 PHP로 개발 된 동일한 웹 사이트를 알고 싶습니다.

두 기술의 성능을 비교하는 실제 시나리오에서 실제 사례가있는 사람이 있습니까?

(나는 여러분 중 일부에게는 이것이 무관하고 어리석은 주장 일 수 있다는 것을 알고 있습니다. 그러나 그것은 주장이며, 저는 여전히 여기에서 훌륭한 사람들의 대답을 듣고 싶습니다)


각 스택의 차이는 결국 동일한 작업을 다르게 수행한다는 것을 의미하고 비교 목적으로 동일한 작업을 수행하면 매우 현실적인 테스트가 아니기 때문에 비교하기가 어렵습니다.

내가 좋아하는 PHP는 모든 요청과 함께로드되고 해석 된 다음 폐기되는 가장 기본적인 형태입니다. 이 점에서 CGI와 매우 비슷합니다 (대략 15 년 정도 된 것을 고려하면 놀라운 일이 아닙니다).

이제 수년에 걸쳐 성능을 향상시키기 위해 다양한 최적화가 이루어졌습니다. 예를 들어 APC를 사용한 opcode 캐싱 (특히 APC가 PHP 6의 표준 부분이되고 지금과 같은 선택적 모듈이 아님)이 그랬습니다.

그러나 여전히 PHP 스크립트는 기본적으로 일시적입니다. 세션 정보는 (일반적으로) 파일 기반이며 상호 배타적입니다 (session_start ()는 session_commit () 또는 스크립트가 완료 될 때까지 동일한 사용자 세션에 액세스하는 다른 스크립트를 차단합니다). 반면 ASP.NET에서는 그렇지 않습니다. 세션 데이터를 제외하고, ASP.NET (또는 ASP.NET이 훨씬 더 유사한 Java)의 응용 프로그램 컨텍스트 내에있는 개체를 갖는 것은 매우 쉽고 (일반적으로) 쉽습니다.

이것이 주요 차이점입니다. 예를 들어 PHP의 데이터베이스 액세스 (mysql, mysqli, PDO 등 사용)는 일시적인 (영구적 연결에도 불구하고) 반면 .Net / Java는 거의 항상 영구적 인 연결 풀을 사용하고이를 기반으로 ORM 프레임 워크 등을 생성합니다. 특정 요청을 넘어선 캐시

바이트 코드 해석 플랫폼 인 ASP.NET은 이론적으로 더 빠르지 만 PHP가 할 수있는 일에 대한 한계가 너무 높아 대부분의 사람들과 관련이 없습니다. 예를 들어 인터넷에서 방문한 상위 20 개 사이트 중 4 개는 PHP입니다. 개발 속도, 견고성, 환경 실행 비용 등은 확장을 시작할 때 이론적 인 속도 차이보다 훨씬 더 중요한 경향이 있습니다.

.Net에는 원시 유형, 유형 안전성 및 PHP가 실행할 수있는 것보다 코드를 더 빠르게 만드는 이러한 종류가 있습니다. 다소 불공평 한 테스트를 수행하려면 두 플랫폼 모두에서 임의의 64 비트 정수 백만 개의 배열을 정렬하십시오. ASP.NET은 기본 유형이고 단순한 배열이 PHP의 연관 배열보다 더 효율적이기 때문에이를 죽입니다 (그리고 PHP의 모든 배열은 궁극적으로 연관성입니다). 게다가 32 비트 OS의 PHP는 네이티브 64 비트 정수를 가지지 않으므로 큰 어려움을 겪을 것입니다.

또한 ASP.NET은 미리 컴파일 된 반면 PHP는 즉석에서 해석되므로 (opcode 캐싱 제외) 차이를 만들 수 있지만 이와 관련하여 PHP의 유연성은 좋은 것입니다. 서버를 바운스하지 않고 스크립트를 배포 할 수 있다는 것은 훌륭합니다. 그냥 넣으면 작동합니다. 훌륭한. 그러나 궁극적으로 성능이 떨어집니다.

궁극적으로 나는 당신이 정말로 무관 한 세부 사항을 주장하고 있다고 생각합니다.


ASP.NET은 더 빠르게 실행됩니다. ASP.NET 개발이 더 빠릅니다. 빠른 컴퓨터를 구입하고 진지한 비즈니스 웹 응용 프로그램을 사용하는 경우 즐기십시오.

ASP.NET 코드는 릴리스 모드에서 빌드되고 최적화되고 캐시 된 등 PHP에 비해 훨씬 더 빠르게 실행됩니다. 그러나 웹 사이트 (Facebook과 같은 대형 플레이어 제외)의 경우에는 덜 중요합니다. 페이지 렌더링 시간의 가장 많은 시간은 데이터베이스 액세스 및 쿼리.

데이터베이스 연결에서 ASP.NET은 훨씬 더 좋습니다. asp.net에서는 일반적으로 개체 쿼리를 SQL 서버 데이터베이스의 저장 프로 시저로 변환하는 LINQ를 사용합니다. 또한 데이터베이스에 대한 연결은 하나의 웹 사이트에 대해 영구적이며 다시 연결할 필요가 없습니다.

이에 비해 PHP는 요청 사이에 SQL 서버 연결을 유지할 수 없으며 데이터베이스를 다시 연결할 때 종종 페이지 렌더링 시간의 20-30 %가 소요됩니다.

또한 전체 웹 응용 프로그램 구성은 각 요청에 대해 PHP로 다시로드되며 asp.net에서는 메모리에 유지됩니다. symfony / symfony2와 같은 대규모 엔터프라이즈 프레임 워크에서 쉽게 볼 수 있습니다. 많은 렌더링 시간은 asp.net이 한 번로드하고 쓸모없는 작업에 서버를 낭비하지 않는 symfony 내부 프로세스입니다.

ASP.NET은 응용 프로그램 메모리의 캐시에 개체를 보유 할 수 있습니다. PHP에서는 파일에 작성하거나 memcache와 같은 해킹을 사용해야합니다. Memcache를 사용하는 것은 동시성 및 위험 문제를 다루는 많은 작업입니다. php는 언어에 뮤텍스 메커니즘이 없기 때문에 개발 시간이 많이 걸리고 항상 작동하지는 않습니다. 따라서 어떤 식 으로든 중요한 섹션을 만들 수 없습니다).

이제 개발 속도에 대해 알아 보겠습니다. ASP.NET에는이를 위해 설계된 두 가지 주요 프레임 워크 (Webforms 및 MVC)가 있으며 환경과 함께 설치되며 PHP에서 오픈 소스 프레임 워크를 가져와야합니다. asp.NET과 같은 PHP에는 표준 프레임 워크가 없습니다.

ASP.NET 언어는 매우 풍부하고, 표준 라이브러리는 PHP 표준 라이브러리가 ... 벗어난 매우 일반적인 문제에 대한 솔루션을 가지고 있습니다. 그들은 하나의 명명 규칙을 유지할 수 없습니다.

.NET에는 유형이 있으며 PHP는 동적이므로 실행하거나 단위 테스트를 작성할 때까지 소스 코드를 제어 할 수 없습니다.

.NET에는 PHP IDE가 평균 또는 평균 수준 인 훌륭한 IDE가 있습니다 (PHPStorm은 여전히 ​​VS + resharper보다 훨씬 더 나쁘거나 심지어 그것 없이도)

Symfony의 PHP 스캐 폴딩은 ASP.NET 스캐 폴딩이 환경에 통합 될 때 명령 줄에서 실행됩니다.

저와 같은 느린 컴퓨터 (하나의 코어 2,2ghz)를 사용하는 경우 PHP 코드가 즉시 새로 고쳐지는 소스 코드 변경시 프로젝트를 다시 컴파일해야하기 때문에 asp.net 페이지를 개발하는 것이 어려울 수 있습니다.

PHP 언어 구문은 C # 구문과 비교할 때 너무 미완성이고 견고하며 헐벗습니다. C #의 강력한 유형과 다양한 유연한 언어 기능은 개발 속도를 높이고 코드 버그를 줄여줍니다.


내 (하드 벤치 마크가 아닌) 경험에서 Asp.Net은 원시 속도 측면에서 확실히 PHP와 경쟁 할 수 있습니다 (일부 영역에서는 PHP를 능가합니다). 그러나 다른 많은 언어 선택 관련 질문과 유사하게 다음 진술은 (이 경우) 유효합니다 (내 의견으로는).

  • 언어 x에 느리고 버그가 많은 사이트가 있습니다 (PHP 또는 Asp.Net)
  • 언어 x (PHP 또는 Asp.Net)로 된 훌륭하고 빠른 사이트가 있습니다.

내가 말하려는 것 : 개발자 (의 재능)는 두 가지 (추상적으로는 거의 동등한) 기술 중에서 선택하는 것보다 전반적인 속도에 더 많은 영향을 미칠 것입니다.

실제로, '전체 속도'비교는 당신이 매우 특정한 전문 틈새 시장에 있지 않는 한 (당신이 우리에게 알리지 않은) 어떤 식 으로든 서로를 따라 잡을 수 있기 때문에 그다지 의미가 없습니다.


ASP.net이라고 말하고 싶습니다.

고려할 사항 :

  • ASP.net은 미리 컴파일되어 있습니다.
  • ASP.net은 일반적으로 PHP보다 빠르게 실행되는 C #으로 작성됩니다.

물론 그 차이는 매우 작습니다. 둘 다 장점이 있습니다. PHP는 배포가 훨씬 쉽고 IIS뿐만 아니라 모든 서버에서 실행할 수 있습니다. 나는 ASP.net MVC를 아주 좋아합니다.


성능 테스트를 마쳤습니다.

프로그램 : 10000000 숫자의 합

여기에 이미지 설명 입력

여기에 이미지 설명 입력

주어진 출력은 php가 C #보다 느리다는 것을 증명합니다 .............


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.


I am a developer expert on both technologies (ASP.Net c# and PHP5). After years and years of working and comparing them in real production environments these are my impressions:

  • First of all, cant compare them making a loop of adding values 1.000.000, this is not a real case.

  • Is not the same comparing them in my development environment than a real production env. Eg: In development ASP.Net does not use IIS by default, use a Inner Development server which has different optimizations. In dev, there is no concurrency.

So my opinion is the next:

  • Looping 1.000.000 times c# is going to be faster.(no-sense)

  • Serving a real page, that access DB, shows images, has forms etc.... ASP.Net is slower than PHP.

  • Weight of ASPX pages is x10 heavier than PHP, so this makes the final user to be waiting more time to get the page.

  • ASPX is slower to develop than PHP, this is important because at the end is money. We develop a 35% faster in PHP than ASP.Net, because of having to compile and restart every time u want to check smthg.

  • In big projects, ASP.Net in long term is better for avoiding errors and have a complex architechture.

  • Because of Windows Servers, IIS, .... at the end u need a powerfull server to hold the same amount of users on ASP than PHP. Eg: We serve with ASP.net arround 20.000 concurrent users and in PHP, the same server can get arround 30.000 users.

The only important thing is not if looping which one is faster. The thing is when website is real and is in production, how many users they can hold, how heavy is the page (heavier== more waiting time from users, more net charge of server, more disk charge of server, more memory charge of server). Try the checking times with concurrency and u will see.

Hope it helps.


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.


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.


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/!


C++... Right now the fight will be between PHP and ASP.NET. PHP will win on ease of use, ASP.NET will win on performance ( in a windows server ecosystem). A lot of the larger websites that started with php have graduated to C++.

참고URL : https://stackoverflow.com/questions/691942/speed-of-code-execution-asp-net-mvc-versus-php

반응형