[UPHPU] performance hit recalling functions?

thebigdog bigdog at venticon.com
Sat Dec 19 16:28:58 MST 2009


On 12/18/09 11:38 PM, Wade Preston Shearer wrote:
> If you are going to be calling a function (such as count() a few times  
> within a script, is there any performance benefit to calling it once  
> at the beginning, storing the result in a value and then using the  
> value instead of recalling the function each time?

the best way to check on this is to use a debugger and see how the method is
called. then you can tell for sure if it is cached or not. however, i doubt that
it would cache the result. that would not make sense to cache the result unless
you explicitly asked it to cache something.

i usually will check the source code and verify that too...for example here is
the source for the 5.3 branch:

http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/standard/array.c?revision=291851&view=markup

if you look at line 298 that will be the start of the count function in php
defined for arrays and objects. one thing that you might notice from the code is
the switch statement and the default value. I have seen some people complain of
the default return value for count.


-- 
thebigdog


More information about the UPHPU mailing list