Page 1 of 1

page loaded in xxx seconds

Posted: Tue Jun 18, 2002 10:41 am
by calebsg
I have seen a few php sites with a little phrase down the bottom usually that says something like "Page load in 0.25 seconds" or something to that effect.

I'd like to do this on my site too so that I can see how fast my MySQL queries are executing and how fast the php page is loading:!: However I have not come across any tutorials on it. Could someone point me in the right direction?

TIA. :D

Posted: Tue Jun 18, 2002 11:36 am
by Wandrer

Code: Select all

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;
          print "<b>Benchmark: $this->t_elapsed seconds</b>";
            return $this->t_elapsed;
        &#125;
    &#125;
&#125;

Code: Select all

<class function here>
   $BenchmarkTimer = new c_Timer;
   $BenchmarkTimer->start();

   <your program here>

   $BenchmarkTimer->stop();
   $BenchmarkTimer->elapsed();

Posted: Tue Jun 18, 2002 3:03 pm
by calebsg
Looks good -- I'll give it a spin later.

Thanks.