How would I time 100 php includes and 100 ssi

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

How would I time 100 php includes and 100 ssi

Post by Luke »

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

Post by Charles256 »

Code: Select all

$a=microtime();
// do all my includes.
$b=microtime();
$time=$b-$a;
echo "page created in $time seconds.";
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Thanks charles :D
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.";
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

page created in -0.486584 seconds.

A negative amount of time?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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";
?>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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]
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Normally you would perform your timing tests multiple times, then take the average.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

OK... does anybody know how I would put in the SSI?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
trukfixer
Forum Contributor
Posts: 174
Joined: Fri May 21, 2004 3:14 pm
Location: Miami, Florida, USA

Post 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.
Post Reply