[nycphp-talk] Switch-Case v. if/else
Elijah Insua
tmpvar at gmail.com
Thu May 14 17:07:33 EDT 2009
+1 for profiling (http://www.xdebug.org/)
I nominate Caching as well.
-- Elijah
On Thu, May 14, 2009 at 4:49 PM, Hans Zaunere <lists at zaunere.com> wrote:
> > Does anyone know how the PHP Interpreter pulls switch/case statements
> > together? Does it emulate a C compiler and, for larger case sets,
> > build a huge if/else cascade? Does it do this always? Is there any way
>
> Since PHP isn't really compiled, there are some inefficiencies when
> compared
> with something like C. I don't remember the exact mechanics, but switch is
> generally slower than if/else and less optimizable (word?) when it comes to
> opcode caching/etc..
>
> > to know when it builds a jump table (like a s/c is supposed to)? I've
> > got a slow script (it's eating ~85% of execution time) that I can't
> > work around and one of the slower parts is a switch case (which is
> > slightly faster than manually building an if/else cascade) and was
> > wondering if anyone had any performance tips for cases like these.
>
> How many cases do you have? Could you refactor into a loop? Are you doing
> string comparisons, or can they be converted to numeric tests? Could some
> of the logic be reduced/spread out into a database or some other process?
>
> H
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090514/3698cdc1/attachment.html>
More information about the talk
mailing list