最近Zend的PHP7已經 處于最后的BUG修復階段,目前 已經更新RC7,對于Zend官方的說法PHP7的性能大約相比PHP5系列版本 提高2倍以上,增加了一些新的語法,摒棄了PHP5的一些影響性能的因素,主要增加了以下Features 。
Improved performance: PHP 7 is up to twice as fast as PHP 5.6 性能比5.6提高2倍 Consistent 64-bit support 64位一致性支持Many fatal errors are now Exceptions 增加許多致命錯誤異常 Removal of old and unsupported SAPIs and extensions 移除了舊的不支持的 SAPIS 和一些擴展The null coalescing operator (??) 空合并運算符 Combined comparison Operator (<=>) 結合比較運算符 Return Type Declarations 和C語言等一樣 顯示的返回值類型Scalar Type Declarations 標量類型定義Anonymous Classes 匿名類!處于好奇的心態我同時安裝了PHP5.5 以及PHP7 RC7 Release,體驗一下 , 于是分別體驗了 PHP7的 性能提升 以及 新語法,至于怎么安裝配置PHP7相信不用我說了,廢話不多說。<?phpfunction microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec);}define('ARRAY_SIZE',20000);function QuickSort($arr,$low,$high){ if($low>$high) return ; $begin=$low; $end=$high ; $key=$arr[$begin]; while($begin<$end) { while($begin<$end&&$arr[$end]>=$key) --$end ; $arr[$begin]=$arr[$end]; while($begin<$end&&$arr[$begin]<=$key) ++$begin; $arr[$end]=$arr[$begin]; } $arr[$begin]=$key; QuickSort($arr,$low,$begin-1); QuickSort($arr,$begin+1,$high);}$time_start = microtime_float();$arr=array();for($i=0;$i<ARRAY_SIZE;$i++){ array_push($arr,rand(1,20000));}QuickSort($arr,0,ARRAY_SIZE-1);$time_end = microtime_float();echo "Bengin:$time_start".'s ';echo "End:$time_end".'s ';echo "TakeTime: ".($time_end-$time_start).'s ';?>1.2 測試結果分別在PHP7和PHP5.5下運行20000隨機數據 快速排序算法之后結果 PHP7是PHP5.5的12倍!!!! 看來PHP7開始要雄起了!
<?phpdeclare(strict_types=1);function GetInt():int{ return 1.0;}echo GetInt();?>
<?phpdeclare(strict_types=1);function GetInt():int{ return 1;}echo GetInt();?>
<?phpdeclare(strict_types=1);function add(int $a,int $b):int{ return $a+$b;}echo add(1,2);?>
<?phpdeclare(strict_types=1);function add(int $a,int $b):int{ return $a+$b;}var_dump(add(1,2));?>var_dump的結果是 int(3)
<?phpdeclare(strict_types=1);function foobar(float $abc): int { return ceil($abc + 1);} try{ foobar(1.22); }catch(Exception $ex){ echo $ex->getMessage(); }?>
<?phpdeclare(strict_types=1);html' target='_blank'>class Foo {public function M1(){echo 'hello,world!';}}$child = new class extends Foo { public function M2(){echo 'hello,world!';return $this;}};$child->M2()->M1();?>
<?phpdeclare(strict_types=1);var_dump(new class(5) { public function __construct($i) { $this->i = $i; }});?>
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答