You will still get the benchmark of the functions, you just declare them
outside of your benchmarking loop so they don't get re-declared.

Pardon my syntax, I'm just going to try to demonstrate (using the
"getmicrotime" function from the PHP manual):

<?php

Function dosomething ($somevar) {
        echo $somevar;
        return 1;
}

Function dosomethingelse ($somevar) {
        echo $somevar;
        return 1;
}

function getmicrotime() 
{ 
    list($usec, $sec) = explode(" ", microtime()); 
    return ((float)$usec + (float)$sec); 
} 


# Benchmark here
$time_start = getmicrotime();
For ($i=0; $i <= 100000; $i++) {
  $retval = dosomething($i);
  $retval2 = dosomethingelse($i);
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
# end benchmarking
?>


Every time you call "dosomething" and "dosomethingelse", it executes the
function, it just doesn't delare it over again.  So even though your
functions are declared outside of your benchmark loop, they still get
executed inside the loop, therefore you get the time needed to execute
100,000 calls of both functions (in this case).

The only thing you're not benchmarking here is the time to declare the
functions once, which is extremely minimal.

Does that clarify it a bit for you?

-TG

> -----Original Message-----
> From: Cristian Lavaque [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, September 14, 2004 1:18 PM
> To: Gryffyn, Trevor
> Subject: Re: [PHP] Benchmarking a script
> 
> 
> Hello Trevor,
> 
> I really appreciate your reply! In fact I haven't found a way 
> to do it 
> yet. I can't really do it the way you suggest cause part of 
> what I want 
> to benchmark is defining the functions. Someone suggested benching it 
> from Apache, but I'm not sure how to do that. Thank you very much for 
> taking the time to drop me an email. :)
> 
> Regards,
> Cristian
> 
> Gryffyn, Trevor wrote:
> > Doesn't look like anyone responded to this (publicly at least).  I
> > wasn't sure if you were still having a problme, but 
> something you might
> > try is putting the function definitions outside of the 
> loop.  They'll
> > get called once, and still be executed within the loop.
> > 
> > Good luck!
> > 
> > -TG
> 
> ______________________________________________________________
> _________________
> This message has been checked by mks_vir mail scanner ( 
http://www.mks.com.pl )

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to