[Python-Dev] _socket efficiencies ideas

Marcus Mendenhall marcus.h.mendenhall@vanderbilt.edu
Wed, 9 Apr 2003 14:14:16 -0500


On Wednesday, April 9, 2003, at 01:49 PM, Martin v. L=F6wis wrote:

> Marcus Mendenhall wrote:
>
>> The getsockaddr call uses them (actually the correct name for one of=20=

>> the flags is AI_NUMERICHOST, not AI_NUMERIC as I originally stated),=20=

>> and its part of the BSD sockets library, which is basically what the=20=

>> python socketmodule wraps.
>
> More importantly, it is part of RFC 2553, which Python uses; it is =
also
> part of Winsock2.
>
>> I guess intercepting all numeric is OK, it is just less efficient=20
>> (since it requires a trial parsing of an address, which is wasted if=20=

>> it is not all numeric), and because it is so easy to implement=20
>> <numeric>.
>
> But isn't the same trial parsing needed to determine presence of the=20=

> "<numeric>" flag? The trial parsing Guido proposes usually stops with
> the first letter in a non-numeric address, and accesses up to 16=20
> letters
> for a numeric address.
Yes, but a compare of the head of a string to a constant is probably=20
something which requires 1% of the cpu time of a sscanf.  Just:
if (string[0]=3D=3D'<' && not strncmp(string,"<numeric>",9)) {whatever}
the first compare avoids even a subroutine call in the most likely case=20=

(string does not begin with <numeric>) but then checks extremely=20
quickly if it is right after that.

Even though cpu time is cheap, we should save it for useful work.

Marcus