[nycphp-talk] Switch-Case v. if/else
John Campbell
jcampbell1 at gmail.com
Thu May 14 17:38:31 EDT 2009
PHP should run ~1M switch tests per second on decent hardware. Either
you are misinterpreting you profiling data, or running a switch
statement a hell of a lot of time. I can't imagine any sort of
if/else vs switch vs. jump table is going to make much of a
difference. At best you will see a speedup of 30% or so, but that
won't really fix the underlying problem.
On Thu, May 14, 2009 at 2:12 PM, Eddie Drapkin <oorza2k5 at gmail.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 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.
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>
More information about the talk
mailing list