How long does the PHP calculation page program execute?

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags code default function list microtime name page program php

How long does the PHP tutorial calculate the time code for the page

function test ()
{
List ($a, $b) = Explode ("", Microtime ());
return (float) $a + (float) $b;
}

$a =test ();
echo $a;
$time = sprintf ("%.12f", (double) test ()-$a); Method Two

Function Ss_timing_start ($name = ' default ') {
      global $ss _timing_start_times;
      $ss _timing_start_times[$name] = explode (', microtime ());
}
Function ss_timing_stop ($name = ' default ') {
      global $ss _timing_stop_times ;
      $ss _timing_stop_times[$name] = explode (', microtime ());
}
Function ss_timing_current ($name = ' default ') {
      global $ss _timing_start_ Times, $ss _timing_stop_times;
      if (!isset ($ss _timing_start_times[$name)) {
           return 0;
     }
      if (!isset ($ss _timing_stop_times[$name)) {
           $stop _time = Explode (", microtime ());
     }
      else {
          $stop _time = $ss _timing_ stop_times[$name];
     }
     //Do the big numbers The Sgt ones aren't ' t lost
       $current = $stop _time[1]-$ss _timing_start_times[$name][1];
      $current + + $stop _time[0]-$ss _timing_start_times[$name][0];
      return $current;
}
Ss_timing_start ();
/**
Below is the code for your page
/
require_once    ' index.php tutorial ';//index.php is the page to test execution time
/*
Page code end
//
Ss_timing_stop ()//Method three

Class Timer
{
var $starttime = 0;
var $stoptime = 0;
var $timespent = 0;

function Start () {
$this->starttime = Microtime ();}
function Stop () {
$this->stoptime = Microtime ();}
function spent () {
if ($this->timespent) {
return $this->timespent;
else {
$startmicro = substr ($this->starttime,0,10);
$startsecond = substr ($this->starttime,11,10);
$stopmicro = substr ($this->stoptime,0,10);
$stops Tutorial Econd = substr ($this->stoptime,11,10);
$start = Doubleval ($startmicro) + $startsecond;
$stop = Doubleval ($stopmicro) + $stops tutorial Econd;
$this->timespent = $stop-$start;
Return substr ($this->timespent,0,8). Seconds ";
}
}//End Function spent ();
}//end class timer;
Example
$timer = new Timer;
$timer->start ();
/*
Your code is here.
*/

$timer->stop ();
echo "Execute this script altogether". $timer->spent ();

Related Article

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.