Performance test comparison between JSP and PHP

Source: Internet
Author: User

The test data is real, but only for reference. Welcome to the discussion.

In addition to comparison, it can also be used by PHP and JSP programmers to optimize their own programs.

I. Arithmetic Operations

A. Test Standards

Loop N times and perform integer auto-increment operation.

B. Test

Test code:

Test Type JSP int integer JSP long integer JSP long integer 2 PHP PHP2
Test code int i=0;
while (i<XXXX)
{
i ;
}

 

 

long l=0;
while (l<XXXX)
{
l ;
}

 

 

long l=0;
while (l<XXXX)
{
l=l 1;
}

 

 

$i=0;
while ($i<XXXX)
{
$i ;
}

 

 

$i=0;
while ($i<XXXX)
{
$i=$i 1;
}

 

 

Test result (unit: milliseconds)

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.

XXXX Value JSP int integer JSPlong integer JSPlong integer 2 PHP PHP2
1000 0 0 0 0-1 0-1
10000 0 0 0 3-4 6-7
100000 0 0 0 (16, 32) 34-35 51-52
1000000 0 (10) 0 (16, 32) 0 (16, 32) 348-368 527-534
10000000 0 (13) 16-32 32-78 3547-3585 5239-5390
100000000 0 (16) 266-281 265-281 35309-35486
1000000000 0 (16,743) 2625-2676 2203-3687

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 is based on the following speculation. 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 ", 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

Test code:

Test Type JSP PHP
Test code String str="";
while (str.length()< XXXX)
{
str ="a";
}

 

 

$str="";
while (strlen($str)< XXXX)
{
$str.="a";
}

 

 

Test result (unit: milliseconds)

XXXX Value JSP PHP
1000 0-16 1
10000 656-703 9-10
100000 105078-105235 95-103

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.

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.