NYCPHP Meetup

NYPHP.org

[nycphp-talk] Switch-Case v. if/else

Anthony Wlodarski ant92083 at gmail.com
Thu May 14 15:42:02 EDT 2009


How many cases are in this switch statement that is causing it to be slow?

-----Original Message-----
From: Eddie Drapkin <oorza2k5 at gmail.com>
Sent: Thursday, May 14, 2009 2:12 PM
To: NYPHP Talk <talk at lists.nyphp.org>
Subject: [nycphp-talk] Switch-Case v. if/else

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090514/af94e3a5/attachment.html>


More information about the talk mailing list