首頁  >  文章  >  後端開發  >  记录页面执行时间php代码

记录页面执行时间php代码

WBOY
WBOY原創
2016-07-25 08:46:02742瀏覽
  1. class runtime
  2. {
  3. var $StartTime = 0;
  4. var $StopTime = 0;
  5. function get_microtime()
  6. {
  7. list($usec, $sec) = explode(' ', microtime());
  8. return ((float)$usec + (float)$sec);
  9. }
  10. function start()
  11. {
  12. $this->StartTime = $this->get_microtime();
  13. }
  14. function stop()
  15. {
  16. $this->StopTime = $this->get_microtime();
  17. }
  18. function spent()
  19. {
  20. return round(($this->StopTime - $this->StartTime) * 1000, 1);
  21. }
  22. }
  23. //例子
  24. $runtime= new runtime;
  25. $runtime->start();
  26. //你的代码开始
  27. $a = 0;
  28. for($i=0; $i{
  29. $a += $i;
  30. }
  31. //你的代码结束
  32. $runtime->stop();
  33. echo "页面执行时间: ".$runtime->spent()." 毫秒";
  34. ?>
复制代码

执行时间, php


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn