Re: Array mysteries
| From: | Richard Lynch | Date: | Mon, 12 Mar 2007 23:21:39 +0000 |
| Subject: | Re: Array mysteries | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250351@lists.php.net to get a copy of this message | ||
On Sun, March 11, 2007 2:57 pm, Edward Vermillion wrote:
> Would the array lookup be faster for a lesser-used option/key in a
> situation where there were quite a few options? (you wouldn't have to
> go through the whole switch to get to the option at the end (?) or
> would you? I have no idea how that all works internally)
Almost for sure, a 'switch' is going to win over the array hash lookup
in almost all cases, as the switch is built into the opcodes, and not
an array hash lookup.
If I understood a thread on Internals last month correctly,
internally, the order of the case statements does matter, somewhat,
but you *DO* have to be calling something a ZILLION times for it to
matter in the real world.
Stressing out over performance instead of maintainability is almost
always the wrong way to start a project.
You don't want to be a complete idiot, but often-times the performance
bottle-neck ends up being somewhere entirely different from where you
expected anyway.
Write the code as straight-forward and maintainable as you can first.
Then measure it for performance to see if it's acceptable.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?