Page load speed

By log2 on Dec 20, 2004

When you go to google and it says, it took 0.000123 seconds to find 123134134 items, and you think to yourself, wow I wish I could see how long it takes to load my page, well now you can! this is another straight forward little piece of code.

<? 

//top of your page 
$gentime = microtime(); 
$gentime = explode(' ',$gentime); 
$gentime = $gentime[1] + $gentime[0]; 
$pg_start = $gentime; 

?> 
<? 

//end of your page 
$gentime = microtime(); 
$gentime = explode(' ',$gentime); 
$gentime = $gentime[1] + $gentime[0]; 
$pg_end = $gentime; 
$totaltime = ($pg_end - $pg_start); 
$showtime = number_format($totaltime, 4, '.', ''); 
echo("This page was generated in " . $showtime . " seconds"); 

?>

Comments

Sign in to comment.
Hawkee   -  Dec 01, 2008

Looks good Quentin, much shorter.

 Respond  
quentin   -  Dec 01, 2008

This could be further reduced to 4 lines of code.. :)

//Put this at the very top of your script:
$start_time=microtime(TRUE);

//Put this at the very bottom/end of your script:
$end_time=microtime(TRUE);
$exec=round($end_time-$start_time, 3);
echo "Page was generated in $exec seconds.";

 Respond  
PuNkTuReD   -  Jun 06, 2008

i gave it an 8 , i may even use it on my site .

 Respond  
F*U*R*B*Y*   -  Jun 06, 2008

Well obviously it displays how long it took for the page to be generated....

 Respond  
T012m3n7oR   -  Jun 06, 2008

wth? explain?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.