Serhiy Storchaka added the comment:

Yes, pickling (and especially unpickling) ints is more efficient, but the code 
will more complex. Interfaces should be pickled as strings for backward 
compatibility, and interfaces are subclasses of addresses.

Here are microbenchmarks:

./python -m timeit -s "import ipaddress, pickle; ips = 
[ipaddress.ip_address('192.0.2.%s'%i) for i in range(1, 101)]" -- 
"pickle.dumps(ips)"
./python -m timeit -s "import ipaddress, pickle; ips = 
[ipaddress.ip_address('2001:db8::%x'%i) for i in range(1, 101)]" -- 
"pickle.dumps(ips)"
./python -m timeit -s "import ipaddress, pickle; ips = 
[ipaddress.ip_address('192.0.2.%s'%i) for i in range(1, 101)]; pickled = 
pickle.dumps(ips)" -- "pickle.loads(pickled)"
./python -m timeit -s "import ipaddress, pickle; ips = 
[ipaddress.ip_address('2001:db8::%x'%i) for i in range(1, 101)]; pickled = 
pickle.dumps(ips)" -- "pickle.loads(pickled)"

Results for unpatched module:
1000 loops, best of 3: 1.56 msec per loop
1000 loops, best of 3: 1.62 msec per loop
1000 loops, best of 3: 1.08 msec per loop
1000 loops, best of 3: 1.09 msec per loop

With ipaddress_pickle.patch:
100 loops, best of 3: 3.43 msec per loop
100 loops, best of 3: 10.6 msec per loop
100 loops, best of 3: 7.76 msec per loop
100 loops, best of 3: 8.58 msec per loop

With ipaddress_pickle_2.patch:
1000 loops, best of 3: 1.11 msec per loop
1000 loops, best of 3: 1.16 msec per loop
1000 loops, best of 3: 1.88 msec per loop
100 loops, best of 3: 2.05 msec per loop

With ipaddress_pickle_3.patch:
1000 loops, best of 3: 1.12 msec per loop
1000 loops, best of 3: 1.15 msec per loop
1000 loops, best of 3: 1.13 msec per loop
1000 loops, best of 3: 1.15 msec per loop

----------
Added file: http://bugs.python.org/file37725/ipaddress_lightweight_2.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to