Jump to content

[SOLVED] Page Load Time: Which is faster and more importantly...precise?


JsusSalv

Recommended Posts

Hello Everyone:

 

I'm trying to add a page load time script to my pages and would like some opinions from the community.  Which script would work best for this purpose:


[b]1):[/b]
<?php
// Place at very bottom of page.
echo ($load = round(microtime(), 5)).'s'; ?>

 

2)

<?php
// Insert this block of code at the very top of page.
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$start = $time;
?>

<?php
// Place this part at the very bottom of page.
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$finish = $time;
$totaltime = ($finish - $start);
printf ("This page took %f seconds to load.", $totaltime);
?>

 

 

I've tested both code blocks on the same page and on separate pages but they produce different results.  I'm also using the Firefox add-on, YSlow, for testing purposes and it too produces a VERY different result.

 

I've also gone to the following websites and again, different results:

1) http://www.websiteoptimization.com/services/analyze/

2) http://tools.pingdom.com/

 

However, both websites did produce almost identical load times.  Would be nice to know what they're using.

 

Can I get some feedback on which code would be best to use on my pages and whether I should be concerned with YSlow's result?  Thanks!

if yer using php5, ya can use microtime(1) or microttime(true)

this way microtime returns a float value already, so unecessary to do the explode trick to convert to a float.

 

<?php
$starttime=microtime(true);
.
.
.
echo "Page load time: ". round(microtime(true)-$startime,5);

 

The first script excertpt ya posted just returns a unix timestamp, which is useless in a display unless ya do something with it.

second one is what ya use to display the load time of a page, but note the above tip

U shud consider that image links arent embedded into a page, they are loaded.

so any web browser tool that shows page loadig times is probably gonna include the image loading as well. which shud be slower than what yer functions display/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.