Re: Re: [PHP-DEV] How expensive are function_exists() calls?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2009-03-04 at 11:45 -0800, mike wrote:
> On Wed, Mar 4, 2009 at 4:01 AM, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
> > ..not an internals question me thinks ... redirecting to generals mailing list
> 
> Actually, I do think it is somewhat internals related.
> 
> I want to know from the internals/experts angle if this is a good
> function to be relying on, or if it is one of those things like the
> "@" operator which I've been told is "expensive" and to me is one of
> those things to stay away from.
> 
> Now if this breaks opcode caches like APC, I will have to find another way.
> 
> Also - I write procedural, not OOP. So that won't help here.
> 
> Would creating functions such as
> 
> output_foo_html()
> output_foo_rss()
> output_foo_json()
> 
> Then depending on the output, using something like this? Would this be
> breaking opcode caches as well then?
> 
> if(function_exists('output_foo_'.$format)) {
>     call_user_func('output_foo_'.$format);
> } else {
>     output_foo_html();
> }

Perfectly fine. Shouldn't break an opcode cache. the opcode cache will
store the opcodes to do what you've done above and also will store
opcodes for the function wherever it was declared. Then when it runs off
it will go. For what it's worth... functions have global scope... all
functions are store in some kind of lookup table. Associative arrays
have O( lg n ) lookup time. Let's imagine you had 1 million defined
functions... We're talking at most 19 node traversals on a balanced
binary tree (yes I know it's a hashing algorithm). A billion declared
functions 29 steps. Is it fast? Yes.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux