RE: ip-to-country - summary
| From: | Derick Rethans | Date: | Fri, 02 May 2003 09:11:04 +0000 |
| Subject: | RE: ip-to-country - summary | ||
| References: | 1 | Groups: | php.mirrors |
| Request: | Send a blank email to php-mirrors+get-17204@lists.php.net to get a copy of this message | ||
On Fri, 2 May 2003, Divyank Turakhia wrote:
> Original:
>
> function i2c_ip2num($dotted)
> {
> $dotted = preg_split("/[.]+/", $dotted);
> return (float) ($dotted[0] * 16777216) +
> ($dotted[1] * 65536) +
> ($dotted[2] * 256) +
> ($dotted[3]);
> }
>
> Suggested Change:
>
> function i2c_ip2num($dotted)
> {
> $dotted = preg_split("/[.]+/", $dotted);
> return ($dotted[0] << 24) | ($dotted[1] << 16) | ($dotted[2] << 8) |
> $dotted[3];
> }
>
>
> Since a multiplication takes 8 cpu cycles while a shift operator takes
> 2, this would give a slight boost.
That might be so in assembly, but definitely not in PHP :) The
difference would be too small to measure, so I opt for the better
readable (Goba's) version.
Derick
--
-------------------------------------------------------------------------
Derick Rethans http://derickrethans.nl/
JDI Media Solutions http://www.jdimedia.nl/
PHP Magazine - PHP Magazine for Professionals http://php-mag.net/
-------------------------------------------------------------------------