How would I time 100 php includes and 100 ssi
Moderator: General Moderators
How would I time 100 php includes and 100 ssi
I need to time 100 server side includes and 100 php includes... how would I do this?
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Code: Select all
$a=microtime();
// do all my includes.
$b=microtime();
$time=$b-$a;
echo "page created in $time seconds.";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.";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";
?>FIXED[/b]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"; ?>
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.
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.
- trukfixer
- Forum Contributor
- Posts: 174
- Joined: Fri May 21, 2004 3:14 pm
- Location: Miami, Florida, USA
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 , 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.
but I would say to do a ssi include ,
Code: Select all
echo "<!--#include virtual="counter.php" -->";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.