PHP Calculation program Run time

Source: Internet
Author: User

Here is a description of microtime () This function, Microtime () not much, but can not know this function, it is to return the current Unix timestamp and the number of microseconds. For example: Echo Microtime (); will return: 0.08845800 1376983061. So you can use the Explode function to split it into an array as a space, then the $starttime[0]=0.08845800 (microseconds), $starttime [1]=1376983061 (the current number of seconds, equivalent to time ().

<?php
Program Run time
$starttime = Explode (' ', Microtime ());
Echo Microtime ();

/*········ Here is the code area */
for ($i =0; $i <1000000; $i + +) {
$i;
}
/*········ The above is the code area */

Program Run time
$endtime = Explode (' ', Microtime ());


$thistime = $endtime [0]+ $endtime [1]-($starttime [0]+ $starttime [1]);
$thistime = Round ($thistime, 3);
echo "This page takes time:". $thistime. "Seconds. ";
?>

PHP Calculation program Run time

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.