[Python-ideas] namedtuple with ordereddict

Giampaolo Rodola' g.rodola at gmail.com
Wed Jul 19 10:28:37 EDT 2017

On Wed, Jul 19, 2017 at 3:27 AM, Steven D'Aprano <steve at pearwood.info>

> On Tue, Jul 18, 2017 at 06:16:26PM -0400, Jim J. Jewett wrote:
> > Then constructing a specific instance from the arguments used to
> > create it could be as simple as keeping a reference to the temporary
> > created to pass those arguments...
> The bottleneck isn't creating the instances themselves, the expensive
> part is calling namedtuple() to generate the named tuple CLASS itself.
> Creating the instances themselves should be fast, they're just tuples.

Still much slower (-4.3x) than plain tuples though:

$ python3.7 -m timeit -s "import collections; Point =
collections.namedtuple('Point', ('x', 'y'));" "Point(5, 11)"
1000000 loops, best of 5: 313 nsec per loop

$ python3.7 -m timeit "tuple((5, 11))"
5000000 loops, best of 5: 71.4 nsec per loop

Giampaolo - http://grodola.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170719/3a9206be/attachment.html>

More information about the Python-ideas mailing list