程序员人生 网站导航

计算一个程序的执行时间的函数

栏目:php教程时间:2014-04-01 11:08:20
计算一个程序的执行时间的函数
  1. function getmicrotime(){ 
  2. list($usec, $sec) = explode(" ",microtime()); 
  3. return ((float)$usec (float)$sec); 
  4. } 
  5.  
  6. $time_start = getmicrotime();//开始计时, 放在程序头 
  7.  
  8. for ($i=0; $i < 1000; $i ){ 
  9. //do nothing, 1000 times 
  10. } 
  11.  
  12. $time_end = getmicrotime();//结束计时, 放在尾部 
  13. $time = $time_end - $time_start; 
  14.  
  15. echo "Did nothing in $time seconds"; 
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐