<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 19, 2017 at 12:10 PM, Giampaolo Rodola' <span dir="ltr"><<a href="mailto:g.rodola@gmail.com" target="_blank">g.rodola@gmail.com</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"><div dir="ltr"><div class="gmail_extra"> Should have been something like this instead:</div><div class="gmail_extra"><div class="gmail_extra"><div class="gmail_extra"></div><div><br></div><div><div>$ python3.7 -m timeit -s "import collections; Point = collections.namedtuple('Point'<wbr>, ('x', 'y')); x = [5, 1]" "Point(*x)"</div><div>1000000 loops, best of 5: 311 nsec per loop</div><div><br></div><div>$ python3.7 -m timeit -s "x = [5, 1]" "tuple(x)"</div><div>5000000 loops, best of 5: 89.8 nsec per loop</div></div></div></div></div></blockquote><div><br></div><div>This looks like a typical python function call overhead.  Consider a toy class:</div><div><br></div><div>$ cat c.py</div><div>class C(tuple):</div><div>    def __new__(cls, *items):</div><div>        return tuple.__new__(cls, items) </div><div><br></div><div>Comparing to a naked tuple, creation of a C instance is more than 3x slower.</div><div><br></div><div><div>$ python3 -m timeit -s "from c import C; x = [1, 2]" "C(*x)"</div><div>1000000 loops, best of 3: 0.363 usec per loop</div></div><div><br></div><div><div>$ python3 -m timeit -s "x = [1, 2]" "tuple(x)"</div><div>10000000 loops, best of 3: 0.114 usec per loop</div></div><div><br></div><div><br></div></div></div></div>