Posted by Edward Z. Yang on 05/19/07 18:23
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ciaran wrote:
> All great ideas guys! Thanks for the replies on this. I especially
> like purcaholic's one! Anyone know which of these methods would be the
> fastest? Are any of them actually any faster than the basic one I
> posted at the start?
Purcaholic's one doesn't work (as it stands: he probably mean to use
strpos) and is probably the slowest.
In terms of speed, it's probably like this (from fastest to slowest):
1. Original method
2. isset($lookup[$var])
3. in_array
4. strstr
If you have a particularly large set of numbers to compare against,
method 2 may end up being faster due to the implementation of
associative arrays needing only a binary search. I would use method 2
simply because it's more maintainable (you can generate the $lookup
array from anywhere you want).
But I should warn you: this is really premature optimization and will
make no difference at all most of the time.
- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org> Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGT0CzqTO+fYacSNoRAt6ZAJ9stC/G1vPm0orjhfegDK6vRvsQhwCeNz9V
iwhkovqnMTPpNIzUXH9Ff9I=
=Qajq
-----END PGP SIGNATURE-----
[Back to original message]
|