php计算查看一段程序代码的运行时间

作为日后备用的功能吧,查看代码执行的效率,mysql有explain函数

方法一:

/*

$starttime = explode(' ',microtime());

 for($i=0;$i<10000000;$i++){  

  $i;

 }

 //程序运行时间

 $endtime = explode(' ',microtime());

 $thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);

 $thistime = round($thistime,3);

 echo "本网页执行耗时:".$thistime." 秒。";  // 0.87s

*/

方法二:

 $StartTime = microtime(true);  

 for($i=0;$i<10000000;$i++){

  $i;

 }

 $StopTime = microtime(true);  

 $TimeSpent=$StopTime-$StartTime;

 echo number_format($TimeSpent*1000, 4).'毫秒';  // 897.6068毫秒

  花半小时安装玩玩PHP7,看看PHP7的效率较PHP5.5比较

  循环一千万次 PHP7大概是184.6490毫秒(上限不到200毫秒),效率大概是5倍左右

猜你喜欢

转载自chenhaibo0806999.iteye.com/blog/2265738