PHP implements class instances to compute execution Time _php tips

Source: Internet
Author: User

The examples in this article describe the classes that the PHP implementation uses to compute execution times. Share to everyone for your reference. Specifically as follows:

With this PHP class, the calculation function or a piece of code execution time 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;}}
;
? >

Examples of usage are as follows:

<?php
  $timer = new C_timer;
  $timer->start ();
  echo " 
 

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.