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

> 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
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to