August
1

Performance is very important to webmasters and a lot of times it would be nice to know how long on average it took for our web pages to load. I created a simple class in order to track how fast a page executes. This is written in PHP because that is what I use to develop my sites. It currently just displays the output on the page; I haven't turned this into a log or database table yet but I probably will. Once I convert it to save the output each time, I could use it to track the averages per page. This is just a basic timer at the moment though. I have included the class and an example within the same PHP file below. You are free to use and change the script as you wish. Feel free to link back if you would like, but it is not mandatory.

<?

class LoadTime {

var $PageLoadStart;
var
$PageLoadEnd;

function PageStart() {
$this->PageLoadStart = microtime();
}

function PageEnd() {
$this->PageLoadEnd = microtime();
}

function LoadTime() {
return
round($this->PageLoadEnd-$this->PageLoadStart,4);
}

}

$timer = new LoadTime();
$timer->PageStart();

$i = 0;
while (
$i<100000) {
$i++;
}

$timer->PageEnd();

echo $timer->LoadTime().' seconds';

?>

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • description
  • Reddit
  • Google
  • Slashdot
  • StumbleUpon
  • Technorati
  • Propeller
  • Mixx
  • Live
  • Ma.gnolia
  • Furl
  • NewsVine
  • Gospel Scoop





Something to say?

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.