一个有趣的php性能测试用例

<?php
$str = array('str'=>'aaa');
$bt = microtime(true);
for($i=0;$i<10000000;$i++){
	//isset($str['str']);        //0.9s       //内置函数 伪函数(对应一条opcode)
	array_key_exists('str',$str); //3.4s  //内置函数
	//nothing();                  //1.7s   //空函数调用开销
	//if (format($str)){}         //3.8    //用户定义函数
}
echo microtime(true) - $bt;
function nothing(){}
function format($str){if ($str['str']){}}


你可能感兴趣的:(性能测试)