PHP and JSP stage super detailed performance test PK

Source: Internet
Author: User
There are many comparisons on the performance of PHP and JSP on the internet. some results show that PHP has much lower performance than JSP. This article will objectively show the performance test comparison between PHP and JSP, all are real data. Of course, this does not include. Net. Test Environment: ◆ hardware: P42.4G, 1 GB memory

There are many comparisons on the performance of PHP and JSP on the internet. some results show that PHP has much lower performance than JSP. This article will objectively show the performance test comparison between PHP and JSP, all are real data. Of course, this does not include. Net.

Test environment:

◆ Hardware: P4 2.4 GB, 1 GB memory

◆ Software: WindowsXP + Apache2.0.54 + PHP4.4.0 + Mysql4.1.14 + Tomcat5.0.28

I. Arithmetic operations

A. test standards

Loop N times and perform integer auto-increment operation.

B. test code

498) this. style. width = 498; "border =" 0 "/>

Test result (unit: milliseconds)

 

498) this. style. width = 498; "border =" 0 "/>

Test result description: m-n indicates that the main fluctuation range is between m and n. n indicates that there are many values or average values, and m (x, y) indicates that x appears occasionally, y. The following are the same.

C. Conclusion

Java's arithmetic operations are well optimized. it is estimated that they directly correspond to CPU commands, and the numeric values are large, so the arithmetic operation performance is stable. It should be noted that the long operation time is longer than the int operation time (after all, it is a 32-bit system). therefore, do not use long when long is not needed, int.

PHP is a weak type of variable, and the arithmetic operation is not satisfactory. it is estimated that it is not an arithmetic operation that directly corresponds to the machine code. The PHP arithmetic operation process is estimated as follows. before the operation, you need to check whether the variable is a numerical value and convert the non-numeric value to a numerical value. for example, PHP can perform this operation: 100 + "zhoutang", and the result is 100. it is precisely because it is a weak type language, coupled with detection and conversion before the operation that leads to low performance of arithmetic operations. PHP's time for a single operation is relatively stable, and the time spent on every 10000 arithmetic addition operations is about 3.5 ms.

Different calculation methods also affect the performance.

II. string operations

A. test standards

String connection operation comparison.

B. test

498) this. style. width = 498; "border =" 0 "/>

Test result (unit: milliseconds)

498) this. style. width = 498; "border =" 0 "/>

C. Conclusion

Java strings are processed by objects. Obviously, Java is far from PHP during string comparison. (Because of string operations, most of them need to be connected. here we only compare the join operations, and roughly compare the substring. The difference between the two is not great)

Many PHP string operations are probably directly called C's string functions, so the efficiency is much higher. In Web development, string connection operations are still frequent (including SQL string generation in many cases). Therefore, in terms of arithmetic operations and string operations, Java (JSP) the advantage is not obvious, and it has its own strengths with PHP.


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.