Re: Re: How can i calculate total process time?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eli wrote:
On top use this:
<?php
$mtime = explode(" ",microtime());
$starttime = $mtime[1] + $mtime[0];
?>

On the end use this:
<?php
$mtime = explode(" ",microtime());
$endtime = $mtime[1] + $mtime[0];
echo "\n\n\n<hr><b>".round($endtime-$starttime,3)." sec</b>";
?>
If you want a nice object oriented solution that's easy to use over and over again which does pretty much the same thing, give this class a whirl.
class page_gen {
//
// PRIVATE - DO NOT MODIFY
//
var $cls_start_time;
var $cls_stop_time;
var $cls_gen_time;

//
// FIGURE OUT THE TIME AT THE BEGINNING OF THE PAGE
//
function start() {
$microstart = explode(' ',microtime());
$this->cls_start_time = $microstart[0] + $microstart[1];
}

//
// FIGURE OUT THE TIME AT THE END OF THE PAGE
//
function stop() {
$microstop = explode(' ',microtime());
$this->cls_stop_time = $microstop[0] + $microstop[1];
}

//
// CALCULATE THE DIFFERENCE BETWEEN THE BEGINNNG AND THE END AND COLOR CODE THE RESULT
//
function gen() {
$this->cls_gen_time = round($this->cls_stop_time - $this->cls_start_time,5);
return $this->cls_gen_time;
}
}


then, on the page you want to time, just put at the top:

require('class.pagegen.php')	// OR WHATEVE YOU NAMED IT
$pagegen = new page_gen();
$pagegen->start();	// START TIMING

then at the end...
$pagegen->stop();	// STOP TIMING
$pagegen->gen();	// RETURN GENERATION TIME

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux