PHP Group will no longer support PHP 4 by the end of this year, so I did this test to make everyone more confident to transfer to the PHP 5 platform, check if PHP 4.x has a better performance than PHP 5. the test results are obvious because PHP 5.x is better than php 4. x is faster than PHP 4.x in both object-oriented and process-oriented scenarios. Therefore, it is necessary for you to migrate to the PHP 5.x platform to experience various functions and performance of the PHP 5.x platform.
Because PHP 5 includes new object models, more new features, and faster processing speed, especially the processing speed of object-oriented Code, although the object-oriented code speed in php 4 is relatively average, however, in PHP5.x, the OSS code speed exceeds the process-oriented speed, so do not doubt the OSS performance. The following test results show all of this.
[Test Environment]
- CPU: Intel Pentium4 2.66 GHz
- Memory: 1 GB
- Disk: 73 GB/SCSI
- OS: FreeBSD 4.11
- Web: Apache 1.3.37
Test tool:AB(You can also use http_load)
Term RPS:Requests per second(Number of requests per second)
Related
Test tool:
AB(You can also use http_load)
Term RPS:
Requests per second(Number of requests per second)
PHP 4.4.2 Test Results]
[Function]
<? Php
Function signin (){
Echo "test ";
}
Signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1047.23/rps
[Class]
Do not instantiate class
<? Php
Class User {
Function signin (){
Echo "test ";
}
}
User: signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1034.98/rps
Instantiation class
<? Php
Class User {
Function signin (){
Echo "test ";
}
}
$ User = new User ();
$ User-> signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1006.14/rps
Class inheritance
<? Php
Class AUser {
Function signin (){}
}
TLS extension ss User extends Auser {
Function signin (){
Echo "test ";
}
}
$ User = new User ();
$ User-> signin ();
?>
Test result: the result of AB-n 10000-c 50 is
992.95/rps
[PHP 5.2.1 test results]
[Function]
<? Php
Function signin (){
Echo "test ";
}
Signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1176.06/rps
[Class]
Do not instantiate class
<? Php
Class User {
Public function signin (){
Echo "test ";
}
}
User: signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1197.17/rps
Instantiation class
<? Php
Class User {
Public function signin (){
Echo "test ";
}
}
$ User = new User ();
$ User-> signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1187.93/rps
Class inheritance and abstraction
<? Php
Abstract class AUser {
Abstract function signin ();
}
Class User extends Auser {
Public function signin (){
Echo "test ";
}
}
$ User = new User ();
$ User-> signin ();
?>
Test result: the result of AB-n 10000-c 50 is
1128.54/rps
[Test Results and Analysis]
[Test Result Data]
Version |
Function Testing |
Do not instantiate class |
Instantiation class |
Class inheritance |
PHP 4.4.2 |
1047.23/rps |
1034.98/rps |
1006.14/rps |
992.95/rps |
PHP 5.2.1 |
1176.06/rps |
1197.17/rps |
1187.93/rps |
1128.54/rps
|
[Result Analysis]
1.In general, we can see that the performance of PHP5.2 is slightly higher than PHP4.4, so do not doubt that the performance of PHP5.2 will be poor, obviously faster than PHP4
2.The parsing performance of classes in PHP4.4 is much slower than that of functions, especially when inheritance is used, therefore, PHP4.4 is more suitable for process-oriented and non-inherited class operations.
3.In PHP5.2, the result is that the class execution speed is faster than the function. It can be seen that the PHP5.2 engine has spent a lot of effort on object-oriented processing. At the same time, both functions and classes have good performance.
4.Through this test, we have reason to upgrade PHP4 to PHP5 when the code is not changed much, and PHP5 is basically backward compatible with PHP4 Code, except for some special code. In addition, PHP Group will not continue to maintain PHP4 after the end of this year, so it is easy to upgrade early.