好吧,我承认我只是为了了解一下这3个函数的效率如何
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float(); // Sleep for a while include(‘test’.$argv[1].’.php’);
$time_end = microtime_float();
$time = $time_end – $time_start;
echo " time use:$time";
$test=array(‘asdfasf’,’asdfasdfasdf’,’asdf’=>’aasqtwetqwet’,161346=>14361235);
for($i=0;$i<10000;$i++)
if(json_encode($test)!=json_encode($test))
break;
echo $i;
$test=array(‘asdfasf’,’asdfasdfasdf’,’asdf’=>’aasqtwetqwet’,161346=>14361235);
for($i=0;$i<10000;$i++)
if(serialize($test)!=serialize($test))
break;
echo $i;
命名为test1.php test2.php test3.php….
执行php test.php 1(这就跑test1.php)了
执行结果是
print_r最慢 0.2左右
serialize和json差不多json稍慢一点。。大概是0.07 0.06的样子
This entry was posted on Monday, May 10th, 2010, 11:45 am and is filed under PHP语言学习. You can follow any responses to this entry through RSS 2.0. You can , or trackback from your own site.