In [1]: x = tuple(range(0,5000000))
In [2]: %timeit x[0:200000]
782 µs ± 8.82 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [3]: %timeit x[0:200]
350 ns ± 4.43 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
So... it looks like larger tuple slices means more time spent, and therefore tuple are a poor datastructure for operations like: (head, tail) = t[0], t[1:]
. (Also see Tim Peters: https://mail.python.org/pipermail/python-list/2003-May/225347.html)
But because tuples are immutable, I would have thought slices could be implemented to reference the data of the original tuple, instead of internally copying the list of data references, as appears to happen. So, what's up what that? Is there a reason they're implemented the slow way?