Home >Backend Development >PHP Tutorial >PHP calculation page execution time code

PHP calculation page execution time code

WBOY
WBOYOriginal
2016-07-25 08:45:071168browse
  1. class c_Timer {
  2. var $t_start = 0;
  3. var $t_stop = 0;
  4. var $t_elapsed = 0;
  5. function start() { $this->t_start = microtime(); }
  6. function stop() { $this->t_stop = microtime(); }
  7. function elapsed() {
  8. if ($this->t_elapsed) {
  9. return $this->t_elapsed;
  10. } else {
  11. $start_u = substr($this->t_start,0,10);
  12. $start_s = substr($this->t_start,11,10);
  13. $stop_u = substr($this->t_stop,0,10);
  14. $stop_s = substr($this->t_stop,11,10);
  15. $start_total = doubleval($start_u) + $start_s;
  16. $stop_total = doubleval($stop_u) + $stop_s;
  17. $this->t_elapsed = $stop_total - $start_total;
  18. return $this->t_elapsed;
  19. }
  20. }
  21. };
  22. /* Here's an example usage:
  23. $timer = new c_Timer;
  24. $timer->start();
  25. echo "
    ";
  26. $timer->stop();
  27. echo $timer->elapsed();
  28. */
  29. ?>
复制代码

执行时间, php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn