Message300748
Since dict preserves insertion order, doubly linked list in OrderedDict
can be removed.
There is small performance improvement for odict creation:
$ curl https://api.github.com/orgs/python/repos > repos.json
$ ./py-patched -m perf timeit --compare-to `pwd`/py-default -s 'from collections import OrderedDict as od; import json; data=open("repos.json").read()' -- 'json.loads(data, object_pairs_hook=od)'
py-default: ..................... 1.53 ms +- 0.01 ms
py-patched: ..................... 1.30 ms +- 0.01 ms
Mean +- std dev: [py-default] 1.53 ms +- 0.01 ms -> [py-patched] 1.30 ms +- 0.01 ms: 1.18x faster (-15%)
And more memory efficient:
$ ./py-default -c 'from collections import OrderedDict; import sys; print(sys.getsizeof(OrderedDict.fromkeys(range(1000))))'
85416
$ ./py-patched -c 'from collections import OrderedDict; import sys; print(sys.getsizeof(OrderedDict.fromkeys(range(1000))))'
36992
But most important benefit is smaller code. It make easy to maintain. |
|
Date |
User |
Action |
Args |
2017-08-23 10:24:19 | methane | set | recipients:
+ methane |
2017-08-23 10:24:19 | methane | set | messageid: <1503483859.09.0.0369181186057.issue31265@psf.upfronthosting.co.za> |
2017-08-23 10:24:19 | methane | link | issue31265 messages |
2017-08-23 10:24:18 | methane | create | |
|