Home > Backend Development > PHP Tutorial > PHP implements class instances used to calculate execution time, php examples_PHP tutorial

PHP implements class instances used to calculate execution time, php examples_PHP tutorial

WBOY
Release: 2016-07-13 09:56:52
Original
858 people have browsed it

php implements a class instance used to calculate execution time, php instance

The example in this article describes a php implementation class used to calculate execution time. Share it with everyone for your reference. The details are as follows:

With this php class, calculating the execution time of a function or a piece of code is simple

<&#63;php
class c_Timer {
var $t_start = 0;
var $t_stop = 0;
var $t_elapsed = 0;
function start() {
$this->t_start = microtime();
}
function stop() {
$this->t_stop = microtime();
}
function elapsed() {
if ($this->t_elapsed) {
   return $this->t_elapsed;
} else {
   $start_u = substr($this->t_start,0,10); 
   $start_s = substr($this->t_start,11,10);
   $stop_u = substr($this->t_stop,0,10);  
   $stop_s = substr($this->t_stop,11,10);
   $start_total = doubleval($start_u) + $start_s;
   $stop_total = doubleval($stop_u) + $stop_s;
   $this->t_elapsed = $stop_total - $start_total;
   return $this->t_elapsed;
  }
 }
};
&#63;>
Copy after login

Usage examples are as follows:

<&#63;php
  $timer = new c_Timer;
  $timer->start();
  echo "<hr>";
  $timer->stop();
  echo $timer->elapsed();
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/986073.htmlTechArticlephp implementation of class instances used to calculate execution time, php examples This article describes the php implementation used to calculate execution time class. Share it with everyone for your reference. The details are as follows: With this...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template