Page 1 of 1
How would I time 100 php includes and 100 ssi
Posted: Fri Nov 11, 2005 12:01 pm
by Luke
I need to time 100 server side includes and 100 php includes... how would I do this?
Posted: Fri Nov 11, 2005 12:02 pm
by Charles256
Code: Select all
$a=microtime();
// do all my includes.
$b=microtime();
$time=$b-$a;
echo "page created in $time seconds.";
Posted: Fri Nov 11, 2005 12:59 pm
by Luke
Thanks charles

Posted: Fri Nov 11, 2005 1:04 pm
by Luke
OK... one problem:
Code: Select all
$a=microtime();
for($i=0;$i<100;$i++){
include("page.inc");
}
$b=microtime();
$time=$b-$a;
echo "page created in $time seconds.";
$a=microtime();
for($i=0;$i<100;$i++){
//I DONT KNOW HOW TO DO Standard Server Side includes!
}
$b=microtime();
$time=$b-$a;
echo "page created in $time seconds.";
Posted: Fri Nov 11, 2005 1:09 pm
by Luke
page created in -0.486584 seconds.
A negative amount of time?
Posted: Fri Nov 11, 2005 1:10 pm
by redmonkey
Code: Select all
<?php
function exectime($start, $end, $precision = 4)
{
list($usec, $sec) = explode(' ', $start);
$start_time = ((float)$usec + (float)$sec);
list($usec, $sec) = explode(' ', $end);
$end_time = ((float)$usec + (float)$sec);
return round(($end_time - $start_time), $_precision);
}
$start_time = microtime();
// do something
$end_time = microtime();
echo "total time: " . exectime($start_time, $end_time) . "\x0a";
?>
Posted: Fri Nov 11, 2005 1:12 pm
by Luke
redmonkey wrote:Code: Select all
<?php
function exectime($start, $end, $precision = 4)
{
list($usec, $sec) = explode(' ', $start);
$start_time = ((float)$usec + (float)$sec);
list($usec, $sec) = explode(' ', $end);
$end_time = ((float)$usec + (float)$sec);
return round(($end_time - $start_time), [b]$precision[/b]);
}
$start_time = microtime();
// do something
$end_time = microtime();
echo "total time: " . exectime($start_time, $end_time) . "\x0a";
?>
FIXED[/b]
Posted: Fri Nov 11, 2005 1:15 pm
by Luke
That test is never even close to the same number... it's like in between .4000 and .6000... I'm about to just scratch this whole thing.
Posted: Fri Nov 11, 2005 1:19 pm
by redmonkey
Normally you would perform your timing tests multiple times, then take the average.
Posted: Fri Nov 11, 2005 1:28 pm
by Luke
OK... does anybody know how I would put in the SSI?
Posted: Fri Nov 11, 2005 1:41 pm
by redmonkey
I can only think of two ways of doing it at the moment.
1.
exec() the file which would normally be brought in/parsed as SSI.
or
2. Write two pages, one with includes one with SSI, then use your timing functions against http requests to both pages.
I would favour option 1 as I think it would be more accurate, but I'm not sure if either method would be the best approach.
Posted: Fri Nov 11, 2005 3:28 pm
by trukfixer
if you have ssh access to the box, or command line, you might check to see if apachebench is available (for apache webserver) I'm sure there's many other benchmark tools, but apachebench is the only one I ever used... hence, most familiar with it..
but I would say to do a ssi include ,
Code: Select all
echo "<!--#include virtual="counter.php" -->";
would be the way to go.. or some such like that ... however, it's debatable if you are actually comparing apples to apples.... but you asked how to do a server side include, that's how I'd do one if I was gonna, via php.. not that I can even imagine why I would want to do a ssi include from a php script
but Im not sure why you want to use php to benchmark a server side include.... again in this case, a good benchmarking tool would do better for you than a home brewed benchmark script, IMHO.