New submission from Stefan Behnel <sco...@users.sourceforge.net>: Follow-up to ticket 10227. The following facts seem to indicate that it would be worth caching constant instances of the slice type, such as in [:] or [:-1].
with cached slice instance: $ ./python -m timeit -s 'l = list(range(100)); s=slice(None)' 'l[s]' 1000000 loops, best of 3: 0.464 usec per loop $ ./python -m timeit -s 'l = list(range(10)); s=slice(None)' 'l[s]' 10000000 loops, best of 3: 0.149 usec per loop $ ./python -m timeit -s 'l = list(range(10)); s=slice(None,1)' 'l[s]' 10000000 loops, best of 3: 0.135 usec per loop uncached normal usage: $ ./python -m timeit -s 'l = list(range(100))' 'l[:]' 1000000 loops, best of 3: 0.499 usec per loop $ ./python -m timeit -s 'l = list(range(100))' 'l[:1]' 10000000 loops, best of 3: 0.171 usec per loop Timings based on Python 3.2 rc2. A quick grep against the py3k stdlib finds 2096 lines in 393 files that use constant slices. ---------- components: Interpreter Core messages: 127804 nosy: scoder priority: normal severity: normal status: open title: Cache constant "slice" instances type: performance versions: Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11107> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com