Functional schmunctional...
wolfram.hinderer at googlemail.com
wolfram.hinderer at googlemail.com
Wed Feb 11 14:24:22 EST 2009
On 10 Feb., 21:28, r0g <aioe.... at technicalbloke.com> wrote:
> def inet2ip(n, l=[], c=4):
> if c==0: return ".".join(l)
> p = 256**( c-1 )
> l.append( str(n/p) )
> return inet2ip( n-(n/p)*p, l, c-1 )
> The results for 10000
> iterations of each were as follows...
>
> 0.113744974136 seconds for old INET->IP method
> 27.7441999912 seconds for new INET->IP method
>
> :-/
That's probably because your new function is broken:
>>> def inet2ip(n, l=[], c=4):
if c==0: return ".".join(l)
p = 256**( c-1 )
l.append( str(n/p) )
return inet2ip( n-(n/p)*p, l, c-1 )
>>> inet2ip(0)
'0.0.0.0'
>>> inet2ip(0)
'0.0.0.0.0.0.0.0'
>>> inet2ip(0)
'0.0.0.0.0.0.0.0.0.0.0.0'
More information about the Python-list
mailing list