php5.2与5.3性能测试对比
2012-09-28 14:13
405 查看
源地址:/article/6442116.html
在递归测试、数值运算测试、字符串操作测试、 类和对象测试上5.3性能明显高于5.2,提升大约15%-40%,不过在内存消耗上5.3大于5.2, IO操作速度基本相同。老大伟志让我做的测试,测试方式也许不是绝对正确还希望大家多多指教,详细代码及测试结果如下:
测试环境
A. 虚拟机 + nginx0.7.67 + php5.2.10
B. 虚拟机 + nginx0.7.67 + php5.3.6
1.测试递归函数
采用交换排序算法对1万个数值元素的数组排序30次,此测试主要测试5.2与5.3在递归调用方面的性能。
测试结果
php5.2.10
Running time:0.2008661031723
Memory usage:1540616
php5.3.6
Running time:0.17402129968007
Memory usage:2134104
2.测试数值计算
对指定范围数值做循环加减法操作.
测试结果
php5.2.10
Running time:0.15911817550659
Memory usage:81240
php5.3.6
Running time:0.13838791847229
Memory usage:625640
3.字符串运算
对字符串做一百万次拼接操作。
测试结果
php5.2.10
Running time:0.30056118965149
Memory usage:12968168
php5.3.6
Running time:0.27767395973206
Memory usage:13512760
4.类和对象速度测试
实例化一百万次指定类并调用其类方法。
5.文件IO操作速度测试
测试建立、删除、检测文件和文件夹及向文件内写入数据。
测试结果
php5.2.10
Running time:0.056291103363037
Memory usage:83392
php5.3.6
Running time:0.057452917098999
Memory usage:628000
在递归测试、数值运算测试、字符串操作测试、 类和对象测试上5.3性能明显高于5.2,提升大约15%-40%,不过在内存消耗上5.3大于5.2, IO操作速度基本相同。老大伟志让我做的测试,测试方式也许不是绝对正确还希望大家多多指教,详细代码及测试结果如下:
测试环境
A. 虚拟机 + nginx0.7.67 + php5.2.10
B. 虚拟机 + nginx0.7.67 + php5.3.6
1.测试递归函数
采用交换排序算法对1万个数值元素的数组排序30次,此测试主要测试5.2与5.3在递归调用方面的性能。
<?php function getMsecTime() { $arr = explode( ' ', microtime() ); return $arr[0] + $arr[1]; } //开始时间 $startTime = getMsecTime(); /** * 快序排序算法 * * @param array $arr * @return array */ function quickSort( $arr ) { if( count( $arr ) > 1 ) { $key = $arr[0]; $min = array( ); $max = array( ); for( $i = 1; $i < count( $arr ); $i++ ) { if( $arr[$i] > $key ) { $max[] = $arr[$i]; } else { $min[] = $arr[$i]; } } $min = count( $min ) > 0 ? quickSort( $min ) : $min; $max = count( $max ) > 0 ? quickSort( $max ) : $max; return array_merge( $min, array( $key ), $max ); } else { return $arr; } } //程序运行时间 $runTimeNum = 0; $runTime = 0; for( $i = 0; $i < 30; $i++ ) { $arr = range( 1, 10000 ); shuffle( $arr ); $arr = quickSort( $arr ); $runTimeNum++; } $runTime = ( getMsecTime() - $startTime ) / $runTimeNum; echo 'Running time:' , $runTime , '<br>'; echo 'Memory usage:' . memory_get_usage(); ?>
测试结果
php5.2.10
Running time:0.2008661031723
Memory usage:1540616
php5.3.6
Running time:0.17402129968007
Memory usage:2134104
2.测试数值计算
对指定范围数值做循环加减法操作.
<?php function getMsecTime() { $arr = explode( ' ', microtime() ); return $arr[0] + $arr[1]; } //开始时间 $startTime = getMsecTime(); $numArr = array( 100 , -100 , 1000 , -1000 , 1 ); //程序运行时间 $runTime = 0; $k = 0; $j = 0; while( $j < 1000000 ) { $j++; $k += $numArr[$j % 5]; } $runTime = getMsecTime() - $startTime; echo 'Running time:' , $runTime , '<br>'; echo 'Memory usage:' . memory_get_usage();
测试结果
php5.2.10
Running time:0.15911817550659
Memory usage:81240
php5.3.6
Running time:0.13838791847229
Memory usage:625640
3.字符串运算
对字符串做一百万次拼接操作。
<?php function getMsecTime() { $arr = explode( ' ', microtime() ); return $arr[0] + $arr[1]; } //开始时间 $startTime = getMsecTime(); //程序运行时间 $runTime = 0; $j = 0; $str = ''; while( $j < 1000000 ) { $j++; $str .= $j . 'abcdefg'; } $runTime = getMsecTime() - $startTime; echo 'Running time:' , $runTime , '<br>'; echo 'Memory usage:' . memory_get_usage();
测试结果
php5.2.10
Running time:0.30056118965149
Memory usage:12968168
php5.3.6
Running time:0.27767395973206
Memory usage:13512760
4.类和对象速度测试
实例化一百万次指定类并调用其类方法。
<?php function getMsecTime() { $arr = explode( ' ', microtime() ); return $arr[0] + $arr[1]; } //开始时间 $startTime = getMsecTime(); class testClass { public $testA; public $testB; public function __construct( $num ) { $this->testA = $num; } public function getNum() { return $this->testA; } }; //程序运行时间 $runTime = 0; $j = 0; $str = ''; while( $j < 1000000 ) { $j++; $a = new testClass( $j ); $a->getNum(); } $runTime = getMsecTime() - $startTime; echo 'Running time:' , $runTime , '<br>'; echo 'Memory usage:' . memory_get_usage();
5.文件IO操作速度测试
测试建立、删除、检测文件和文件夹及向文件内写入数据。
<?php function getMsecTime() { $arr = explode( ' ', microtime() ); return $arr[0] + $arr[1]; } //开始时间 $startTime = getMsecTime(); //程序运行时间 $runTime = 0; $j = 0; while( $j < 1000 ) { $j++; $fileName = './' . $j . 'test.txt'; if( file_exists( $fileName ) ) { unlink( $fileName ); } file_put_contents( $fileName , $j ); $fileDir = './' . $j . 'fileDir'; if( is_dir( $fileDir ) && file_exists( $fileDir ) ) { rmdir( $fileDir ); } mkdir( $fileDir , 0777); $j++; } $runTime = getMsecTime() - $startTime; echo 'Running time:' , $runTime , '<br>'; echo 'Memory usage:' . memory_get_usage();
测试结果
php5.2.10
Running time:0.056291103363037
Memory usage:83392
php5.3.6
Running time:0.057452917098999
Memory usage:628000
相关文章推荐
- php5.2与5.3性能测试对比
- PHP 5.3和5.2在递归、尾递归方面的性能测试_ideal
- PHP 5.2、5.3、5.4、5.5、5.6 版本对比及功能详解
- 关于doitphp,thinkphp,yii,ci,doophp等框架的性能对比测试
- php5.3 XHProf性能测试
- php5.3/php5.4与之前的版本差异以及(php5.2x/php5.4x性能对比)
- C#、PHP与NodeJs性能测试对比
- 【转】给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof
- PHP 5.2 5.3 5.5 5.4 5.6 对比以及功能详解
- 关于doitphp,thinkphp,yii,ci,doophp等框架的性能对比测试
- PHP 5.2、5.3、5.4、5.5、5.6 版本区别对比以及新功能详解
- PHP 5.2 5.3 5.5 5.4 5.6 对比以及功能详解
- 给CentOS6.3 + PHP5.3 安装PHP性能测试工具 XHProf-0.9.2
- php缓冲器:eaccelerator与xcache性能测试对比
- PHP 5.2、5.3、5.4、5.5、5.6 对比以及功能详解
- PHP 5.2、5.3、5.4、5.5、5.6 对比以及功能详解
- 给CentOS6.3 + PHP5.3 安装PHP性能测试工具 XHProf-0.9.2
- PHP 5.2、5.3、5.4、5.5、5.6 对比以及功能详解
- 给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof_0.10.3_php53_vc9.dll
- Impala、Hive性能简单对比测试