Re: Re: How can i calculate total process time?
| From: | James Williams | Date: | Sun, 06 Mar 2005 18:36:01 +0000 |
| Subject: | Re: Re: How can i calculate total process time? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210101@lists.php.net to get a copy of this message | ||
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