Home >Backend Development >PHP Tutorial >PHP class to calculate execution time

PHP class to calculate execution time

墨辰丷
墨辰丷Original
2018-06-11 15:11:021230browse

This article mainly introduces the classes used to calculate execution time in PHP. It analyzes the class examples and related usage techniques of PHP calculation and operation implementation. It is of great practical value. Friends in need can refer to it

The example in this article describes the PHP class used to calculate execution time. The details are as follows:

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

<?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;
  }
 }
};
?>

Usage examples are as follows:

<?php
  $timer = new c_Timer;
  $timer->start();
  echo "<hr>";
  $timer->stop();
  echo $timer->elapsed();
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php implements the detection and completion function for the end tag in html tags

php example analyzes the concept of class constants in php

PHP implements the batch upload function for specified suffix files

The above is the detailed content of PHP class to calculate execution time. For more information, please follow other related articles on the PHP Chinese website!

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