note 53526 added to control-structures.switch

From: Date: Sat, 04 Jun 2005 22:24:27 +0000
Subject: note 53526 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-89925@lists.php.net to get a copy of this message
I haven't seen anything specifically pointing this out, but you can get a small performance increase in your code by re-structuring your complex switch statements. For example, I was using the following switch to convert textual month names into their numerical counterparts from the Date header of email on my pop server: switch ($month_name) { case "Jan": case "January": $month = "1"; break; ... } Even just looping through 15 emails on the server, it would take upwards of around 9-10 seconds! So, I decided to shorten my switch statement to something like this: switch ($month_name) { case ("Jan" || "January"): $month = "1"; break; ... } Doing this I actually shaved 3 seconds from my script's execution time!!! I thuoght this was well worth noting for other coders out there who are looking to optimize their PHP code. ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53526 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53526&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53526&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53526&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53526&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53526&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53526&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89925) next »