Home  >  Article  >  Backend Development  >  Record page execution time php code

Record page execution time php code

WBOY
WBOYOriginal
2016-07-25 08:46:02784browse
  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. //Example
  24. $runtime= new runtime;
  25. $runtime->start();
  26. //Your code starts
  27. $a = 0;
  28. for($i=0; $i<1000000; $i++)
  29. {
  30. $a += $i;
  31. }
  32. //End of your code
  33. $runtime->stop();
  34. echo "Page execution time: ".$runtime->spent()." milliseconds";
  35. ?>
Copy code

Execution time, 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