Closed GoogleCodeExporter closed 9 years ago
Hi Matt (F.),
Just noticed what I believe is a bug in your patch
(http://codereview.appspot.com/67107).
Have a look :-
In [1]: from ipaddr import *
In [2]: addresses = [IP(ip) for ip in IP('1.1.1.0/24')]
In [3]: addresses.extend([IP(ip) for ip in IP('::1.1.1.0/120')])
In [4]: len(addresses)
Out[4]: 512
In [5]: addresses[0], addresses[255], addresses[256], addresses[511]
Out[5]: (IPv4('1.1.1.0/32'), IPv4('1.1.1.255/32'), IPv6('::101:100/128'),
IPv6('::101:1ff/128'))
In [6]: CollapseAddrList(addresses)
Out[6]: [IPv4('1.1.1.0/24')] # incorrect
Should be :-
In [6]: CollapseAddrList(addresses)
Out[6]: [IPv4('1.1.1.0/24'), IPv6('::1.1.1.0/120')]
Regards,
Dave M.
Original comment by drk...@gmail.com
on 26 May 2009 at 1:45
Hi Dave,
Thanks for trying it out. I interpreted the docstring in
collapse_address_list():
"addresses: A list of IPv4 or IPv6 objects."
as meaning 'addresses' should contain only IPv4 or only IPv6 addresses, not IPv4
*and* IPv6 addresses.
I've noticed that there isn't an existing test case for this either.
Can someone clarify the intent here?
Is it a valid use case?
regards
Matthew Flanagan
Original comment by mattimus...@gmail.com
on 26 May 2009 at 8:13
The new Patch Set 5 at http://codereview.appspot.com/67107 now works against
2.0.x
branch and is up to 2 times faster than my previous versions.
Original comment by mattimus...@gmail.com
on 19 Aug 2009 at 12:41
hey Matt,
I thought your original patch sped up the execution of collapse_address_list as
well,
no?
the ipaddr-py2 directory has your patch applied, ipaddr-py doesn't:
pmoody@pmoody - (0) - 11:41 - ~/src
-> (cd ipaddr-py; python -m timeit 'import ipaddr;
ipaddr.collapse_address_list([ipaddr.IP(x) for x in ipaddr.IP("1.1.1.0/24")])')
10 loops, best of 3: 121 msec per loop
pmoody@pmoody - (0) - 11:41 - ~/src
-> (cd ipaddr-py2; python -m timeit 'import ipaddr;
ipaddr.collapse_address_list([ipaddr.IP(x) for x in ipaddr.IP("1.1.1.0/24")])')
10 loops, best of 3: 126 msec per loop
I could just be miss remembering something
Original comment by pmo...@google.com
on 19 Aug 2009 at 6:42
Hi Peter,
The optimization is for a list of IP addresses not a list of /32's which are
IPv4Network's. Try:
(cd ipaddr-py2; python -m timeit 'import ipaddr;
ipaddr.collapse_address_list([x for
x in ipaddr.IP("1.1.1.0/24")])')
I'll look at what I can do to make it work for IPv*Networks that are /32's or
/128's
as well.
Original comment by mattimus...@gmail.com
on 19 Aug 2009 at 10:43
Patch Set 6 is uploaded to Reitveld with optimization for a list of networks.
mflanaga:~/src/ipaddr-py$ python -m timeit 'import ipaddr;
ipaddr.collapse_address_list([ipaddr.IP(x) for x in ipaddr.IP("1.1.1.0/24")])'
10 loops, best of 3: 70 msec per loop
mflanaga:~/src/ipaddr-py-2.0.x$ python -m timeit 'import ipaddr;
ipaddr.collapse_address_list([ipaddr.IP(x) for x in ipaddr.IP("1.1.1.0/24")])'
100 loops, best of 3: 13 msec per loop
mflanaga:~/src/ipaddr-py-2.0.x$ python -m timeit 'import ipaddr;
ipaddr.collapse_address_list([x for x in ipaddr.IP("1.1.1.0/24")])'
100 loops, best of 3: 3.02 msec per loop
With attached benchmark scripts:
mflanaga:~/src/ipaddr-py$ python collapse_test.py
CollapseAddrList: 62.501075983 s
mflanaga:~/src/ipaddr-py-2.0.x$ python collapse_test2.py
CollapseAddrList IPs: 0.83060002327 s
CollapseAddrList nets: 0.989233970642 s
Original comment by mattimus...@gmail.com
on 20 Aug 2009 at 12:47
Attachments:
fixed in r95. thanks, Matt!
new:
(cd ipaddr-issue17 ; python -m timeit 'import ipaddr
ipaddr.collapse_address_list([ipaddr.IP(x) for x in ipaddr.IP("1.1.1.0/24")])')
10 loops, best of 3: 11.7 msec per loop
vs. old:
(cd ipaddr-py ; python -m timeit 'import ipaddr
ipaddr.collapse_address_list([ipaddr.IP(x) for x in ipaddr.IP("1.1.1.0/24")])')
10 loops, best of 3: 125 msec per loop
Original comment by pmo...@google.com
on 21 Aug 2009 at 5:12
Original issue reported on code.google.com by
mattimus...@gmail.com
on 26 May 2009 at 12:30