Php7性能测试
来自技术开发小组内部wiki
跳过官方介绍的那些语法特性,今天我就对PHP7的安装和它的实质性能提升做分享
一,安装:
#make -p /data/php7
#cd /data/php7
#tar -xvzf php-7.0.0alpha1.tar.gz
#cd php-7.0.0alpha1
//重新编译可以用(make clean)
//网上流传
#./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache
#make
报错:
ext/xmlrpc/libxmlrpc/.libs/encodings.o: In function `convert':
/home/yaoweibo/php-src-master/ext/xmlrpc/libxmlrpc/encodings.c:74: undefined reference to `libiconv_open'
/home/yaoweibo/php-src-master/ext/xmlrpc/libxmlrpc/encodings.c:82: undefined reference to `libiconv'
/home/yaoweibo/php-src-master/ext/xmlrpc/libxmlrpc/encodings.c:102: undefined reference to `libiconv_close'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
编辑Makefile ,找到EXTRA_LIBS 这一行,在最后面加上 -liconv 重新make
还是在make的时候,报错:
PEAR package PHP_Archive not installed: generated phar will require PHP’s phar extension be enabled.
没管它,接着
#make install,
也跟着报错:
Fatal error: Call to undefined function mysql_connect()
不支持 mysql_connet
配置:
cp php.ini-production /usr/local/php7/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
chmod +x /etc/init.d/php7-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
查看PHP版本:
/usr/local/php7/bin/php -v
PHP 7.0.0alpha1 (cli) (built: Jun 15 2015 17:08:10)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
安装完成
二,测试
性能测试:
求0–200000之间的素数,并把得出来的素数以数组的形式存储,再把数组冒泡出来:
public function sushu($a,$b){
if($b<$a) return;
$temp = array();
for($i=$a;$i<=$b;$i++)
{
$j = intval(sqrt($i));
$flag = true;
if($i<=3)
{
$temp[$i] = $i;
}else
{
for($x=2;$x<=$j;$x++)
{
if($i%$x==0)
{
$flag = false;
break;
}
}
if($flag)
{
$temp[$i] = $i;
}
}
}
//print_r($temp);
return $temp;
}
//冒泡
public function maopao(&$arr)
{
if(!empty($arr))
{
for($i=0;$i<count($arr);$i++)
{
if($arr[$i]>$arr[$j])
{
//开始交换
$temp = $arr[$i];
$arr[$i] = $arr[$j];
$arr[$j] = $temp;
}
}
}
return $arr;
}
public function get_maopao($a,$b){
$array = $this->sushu($a,$b);
//print_r($array);
$ret = $this->maopao($array);
//print_r($ret);
}
下边是测试结果:
[fumubang@dev public_html]$ /usr/local/php7/bin/php index.php local cmdrun test_new get_maopao 0 200000
[2015-06-17 03:44:48]--start to run
[2015-06-17 03:44:49]--finish to run
[2015-06-17 03:44:49]--spend time:0.46 s
[fumubang@dev public_html]$ /usr/local/php5.3/bin/php index.php local cmdrun test_new get_maopao 0 200000
[2015-06-17 11:44:54]--start to run
[2015-06-17 11:45:34]--finish to run
[2015-06-17 03:44:48]--start to run
[2015-06-17 03:44:49]--finish to run
[2015-06-17 03:44:49]--spend time:0.46 s
[fumubang@dev public_html]$ /usr/local/php5.3/bin/php index.php local cmdrun test_new get_maopao 0 200000
[2015-06-17 11:44:54]--start to run
[2015-06-17 11:45:34]--finish to run
[2015-06-17 11:45:34]--spend time:40.60 s
擦,结果汗颜了,相差几百倍