ASP. NET and PHP: more equitable test scenario

Source: Internet
Author: User
Tags apc sql server driver drupal

The execution speed of ASP. NET and PHP is usually the first impression that PHP is faster. There was a blog post by Joe Stagner last month on ASP. NET and PHP are compared again, and the result is ASP. NET performance is superior. This is also mentioned in Justin James's blog, so BKJIA has also been concerned about it ). But this is not over yet: this topic will certainly attract a lot of discussion, and Joe also conducted the second round of testing. So recently, InfoQ Zhao Yu summarized the debate between the two sides as follows:

Last month, Joe Stagner published a series of articles on the blog comparing the execution performance of PHP and ASP. NET, which caused a lot of responses from programmers on both sides. Joe said he would continue this test and look for a more appropriate way to draw conclusions that are as valuable as possible for the actual project.

Joe:

Generally,The purpose of performance testing is to try to prove that one party is faster than the other party.. I am employed by Microsoft and write PHP and ASP. NET code at the same time. I used PHP before. NET. I like it very much.

Therefore, it is difficult for me to tell which one is better. When I talk about PHP, my Microsoft colleagues will write a letter to criticize me. When I post comments that tend to be ASP. NET, my PHP friends will say that I am the trust of Microsoft.

I did this test because everyone has their own views on PHP performance. Windows vs. Linux & 5.2 vs. 5.3), but no one can give clear data.

According to Joe's description,Test EnvironmentAs follows:

  1. All tests run Toshiba Tecra M5 with 4 GB memory and 60 GB 7200 RPM hard drive on the same machine ).
  2. Ubuntu 9 and Windows Server 2008 Standard Edition are installed on independent but identical hard disks.
  3. Linux uses Apache2 and Windows uses IIS 7 as their respective Web servers.
  4. The operating systems of both parties have completed patches or upgrades.
  5. Both systems and runtime are not performing any extra performance enhancement.

From the experiment results,PHP has different performance in Linux and Windows.:

  1. Pure statement execution is better on Windows.
  2. Function calls are faster on Windows.
  3. Object creation and access are faster for PHP 5.2 in Linux, but faster for PHP 5.3 in Windows.
  4. Class Library calls are much faster in Linux, for example, encryption on Ubuntu is 3 to 5 times faster than that on Windows ).
  5. The file access performance in Linux is slightly higher than that in Windows, but the file replication performance in Windows is 60% slower than that in Linux, probably because of the advanced ACL security.
  6. Accessing MySQL on Linux is much faster than Windows, and running PHP 5.3 on Windows is worse. However, from the perspective of PostgreSQL below, this should be due to poor implementation ).
  7. PostgreSQL's performance on the two platforms is very close to the gap of 1000 operations within 0.06 seconds)-whether it is PHP 5.3 or PHP 5.2, Windows performance is slightly better.
  8. On Windows, the performance of PHP 5.2 to access ms SQL Server is slightly inferior to that of MySQL on Linux. At this time, SQL Server for PHP 5.3 is not supported ).

In Joe's opinion, this indicates:

  1. We can think that for pure PHP Execution performance, Linux and Windows are almost the same, which will not be the decisive factor for choosing Linux or Windows as the deployment platform.
  2. If you are building an application, PostgreSQL may be a better choice. Because it performs well on both platforms.
  3. If your application must use MySQL, you need to plan the scalability before selecting Windows. I personally think Sun is unlikely to optimize MySQL performance for Windows ).
  4. The SQL Server Driver in the first PHP version is slower than MySQL or PostpreSQL, but this should not be a problem. The drive of the second version is under development, which will improve the performance.

In Joe's opinion,The PHP and IIS teams have achieved great success in terms of execution performance.Then, the teams of open-source programs, such as Drupal, WordPress, and Joomla, are required to optimize the performance of each platform.

However, apart from the file copy operation,ASP. NET outperforms PHP in terms of performanceWhether deployed on Linux or Windows ):

  1. The performance of accessing MySQL on Linux is slightly better than that of accessing SQL Server on Windows using common data types and SELECT statements ). However, the gap is almost negligible.
  2. ASP. NETC #) operations, such as object usage and class library calls, have far higher performance than PHP.

For this test result, Joe added:

I know some of my PHP friends and Linux guys are about to jump out and refute my tests and results. :)

I have been thinking about whether to add some advanced Optimization Options for such performance comparison. However,. NET also supports multithreading, asynchronous requests, and various caching methods.

Please note -- I didn't say "ASP. NET is faster, so you shouldn't use PHP !", In my opinion, PHP is too simple to make it difficult for some advanced applications, just like ASP. NET will have learning complexity in the early stage of the project.

For me, the most exciting thing about PHP is not its language/platform, but thousands of smart PHP developers, and a variety of excellent projects such as Drupal, Joomla, WordPress, PHPBB, Nuke, etc ).

So we can think that the performance of PHP on Windows and Linux is at the same level. Now I can write PHP class libraries for Windows that I hope for many years.

Joe also published the test code. He said that if you have doubts about the test results, you can perform the experiment yourself or write your own test code for testing.

After the article was published, many netizens expressed their views on the test results. Joe basically replied to the main points one by one:

"I only use ASP. NET because I like Visual Studio IDE" -- I personally think Visual Studio is the most productive development tool. However, PHP has a good choice. I use Zend Studio, PHPEd, Komodo, Delphi for PHP, and these are all very good. I hate Eclipse, but Zend also makes a lot of extensions for PHP development.

Compare ASP performance-no, thanks.There is a big gap between the old ASP and the current PHP and ASP. NET.. It seems that ASP is recommended to be used to develop a new project. I strongly recommend that you do not do this.

Comparison between 32-bit and 64-bit systems-these tests are not designed to reflect performance gaps in 64-bit systems. In future tests, I will add 64-bit scenarios.

"PHP is ugly"-oh, I don't agree. Old ASP is much more ugly. You can write terrible and ugly PHP code, and write ugly and terrible C # Or VB code. Similarly, you can write an elegant C ++ style PHP. This is only related to developers' skills.

Apache on Windows should be used for testing-Apache is a Linux server, but I think that if you do not use IIS 7 on Windows, too much will be lost.

"Is there a way to speed up file copy performance without compromising security in Win2K8 ?" -- It does not seem to work. I think this involves the ACL system on the Windows server. In the future, I may test the performance of reading files through data streams, and the performance of some things may be improved. However, Web applications generally do not program to copy a large number of files.

"PHP has always been, and it will always be a semi-professional environment. On the PHP platform, there are many professional, high-quality applications, and many highly respected developers. Whether it is professional is a problem for developers, not PHP or ASP. NET.

"I think PHP without opcode cache is unfair ,. NET is compiled and executed, and PHP needs to explain and 'compile 'the page each time. I agree that this test may not be complete, but I do not agree with this logic. The Method for Testing PHP is the same as that for downloading and installing PHP. No op-code cache is installed on my VM. In fact, adding this feature to ASP. NET does not mean testing is unfair because PHP lacks this feature-but this requirement is reasonable and I am preparing a new test.

"It is unreasonable to say that PHP is not a 'professional 'language, because almost all of the largest websites are built using PHP."-this is not true, however, it is also wrong to say that those sites are "Almost all" built with PHP. Some are, some are not.

Joe added:

If you see this data, I am naturally very happy to have more confidence in ASP. NET. If I don't think. NET is a better choice for developing Web applications-at least not on other platforms, then I won't work at Microsoft.

But ...... If you ignore PHP because of this data, it is also a wrong and naive behavior.

From a purely technical perspective, I think. NET is far more powerful than PHP, but this does not mean PHP is not powerful enough. In my opinion, the power of PHP is embodied in a large number of applications and available frameworks.

About a week later,Joe made public the results of the second test.. Compared with the previous test, the second test has the following two major changes:

  1. The op-code cache is installed for Linux and Windows, and most tests are re-run.
  2. Due to some dependency problems, the testing platform of PHP 5.3 + APC has become the Debain 5 Operating System.

For the second test and its results, Joe explains:

From the results, the performance gap between running PHP on Ubuntu and Debian is negligible. The performance of some items is slightly improved, while that of some items is 25%, but the overall performance is lower than I imagined.

After APC is used, the running of some items slows down, but I think this is only the error caused by the machine. Note that not the first result shown in the table is refreshed twice, and the result is obtained when the cache hits.

I think the current test is very fair.

Empty loop tests and empty function execution are very important because they reflect the basic consumption of languages or platforms. This is an important consideration for performance consumption outside of performance overhead such as page transmission.

Some of my PHP friends also agree on the accuracy of this test, but I am very insightful to add:

  1. ASP. NET's leading performance won't have any impact on me. PHP is my favorite, and my applications are fast enough.
  2. Yes, ASP. NET is faster in terms of basic performance, but my applications can supplement this part of performance through excellent page implementation and JavaScript practices.
  3. I am developing Drupal, and I am most familiar with PHP, so I would rather spend more hardware to maintain better development efficiency.

These are all good comments!

In addition, according to the results of the previous experiment, when running PHP on the Windows platform, there were some performance problems with MySQL and file access. Many Microsoft teams obtained relevant information from me. We hope this data can be converted into practical improvements.

Joe said he will collect test scenarios that everyone thinks are more fair and meaningful. The following are the testing projects he planned:

  1. Actual Page Test: cyclic, cold/hot calls, and object operations are a type of test, but the overall presentation of the page is another meaningful test.
  2. Load Testing: Which environment can process more requests at the same time.
  3. In the load test, the performance of which side will decrease faster.
  4. What is the performance of the 64-bit platform in various situations.

PHP performance tests on Linux and Windows platforms have also been conducted in China. InfoQ once reported that Microsoft made public the performance evaluation results of its previous cooperation with Kang shengchuangxiang at the WordCamp China 2009 Conference: Running PHP on Windows Server 2008 + IIS, from the average time, the number of requests processed per second and the data throughput are much more convenient than the Linux + Apache hosting method.

What do you think about the performance comparison between ASP. NET and PHP?

  1. Php asp. NET contest
  2. Advantages and disadvantages of PHP and ASP. NET
  3. Overview of advantages and disadvantages of Java,. Net, PHP, and Ruby
  4. Programming Language ranking in September: a historic breakthrough in PHP
  5. ASP. NET JSP PHP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.