Last active
December 14, 2015 14:55
-
-
Save ssato/2367ca4fce99157ecc07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In [3]: import collections | |
| In [4]: import anyconfig | |
| In [5]: ips = anyconfig.load("/tmp/fleure-tests-ouZIjr/packages.json")["data"] | |
| In [6]: ips[0] | |
| Out[6]: | |
| {u'arch': u'x86_64', | |
| u'buildhost': u'x86-007.build.bos.redhat.com', | |
| u'epoch': 12, | |
| u'id': u'0020d156c85b2e2377ea0b8ffc00b3bd4c4a5012', | |
| u'name': u'dhclient', | |
| u'origin': u'redhat', | |
| u'rebuilt': False, | |
| u'release': u'34.P1.el6_4.1', | |
| u'replaced': False, | |
| u'summary': u'Provides the dhclient ISC DHCP client daemon and dhclient-script', | |
| u'vendor': u'Red Hat, Inc.', | |
| u'version': u'4.1.1'} | |
| In [7]: # ... | |
| In [8]: NEVRA = collections.namedtuple("NEVRA", "name epoch version release arch") | |
| In [9]: make_nevra = lambda p: NEVRA(*(p[k] for k in "name epoch version release arch".split())) | |
| In [10]: %memit [make_nevra(p) for p in ips] | |
| peak memory: 38.29 MiB, increment: 0.15 MiB | |
| In [11]: make_nevra_dict = lambda p: dict((k, v) for k, v in p.items()) | |
| In [12]: %memit [make_nevra_dict(p) for p in ips] | |
| peak memory: 38.31 MiB, increment: 0.00 MiB | |
| In [13]: # ... | |
| In [14]: %memit [[make_nevra_dict(p) for p in ips] for _ in range(1000)] | |
| peak memory: 457.00 MiB, increment: 418.69 MiB | |
| In [15]: %memit [[make_nevra(p) for p in ips] for _ in range(1000)] | |
| peak memory: 384.84 MiB, increment: 39.76 MiB | |
| In [16]: make_nevra_odict = lambda p: collections.OrderedDict((k, v) for k, v in p.items()) | |
| In [17]: %memit [[make_nevra_odict(p) for p in ips] for _ in range(1000)] | |
| peak memory: 1573.24 MiB, increment: 1227.63 MiB | |
| In [18]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment