<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 19, 2017 at 3:27 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Tue, Jul 18, 2017 at 06:16:26PM -0400, Jim J. Jewett wrote:</span><span class="gmail-"><br>
> Then constructing a specific instance from the arguments used to<br>
> create it could be as simple as keeping a reference to the temporary<br>
> created to pass those arguments...<br>
<br>
</span>The bottleneck isn't creating the instances themselves, the expensive<br>
part is calling namedtuple() to generate the named tuple CLASS itself.<br>
Creating the instances themselves should be fast, they're just tuples.<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>Still much slower (-4.3x) than plain tuples though:</div><div><br></div><div><div><div>$ python3.7 -m timeit -s "import collections; Point = collections.namedtuple('Point', ('x', 'y'));" "Point(5, 11)"</div><div>1000000 loops, best of 5: 313 nsec per loop</div><div><br></div><div>$ python3.7 -m timeit "tuple((5, 11))"</div><div>5000000 loops, best of 5: 71.4 nsec per loop</div></div></div></div><br><div class="gmail_signature"><div dir="ltr"><div>Giampaolo - <a href="http://grodola.blogspot.com" target="_blank">http://grodola.blogspot.com</a></div><div><br></div></div></div>
</div></div>