[issue3459] optimize bytes.join()

Antoine Pitrou report at bugs.python.org
Mon Jul 28 20:51:27 CEST 2008


New submission from Antoine Pitrou <pitrou at free.fr>:

When the separator is empty and the sequence only contains one non-empty
item, it is possible to optimize b"".join([...]) by simply returning the
non-empty item.

Since b"".join() is the recommended idiom to join large strings
together, I think it can be useful. I encountered this when trying to
optimize io.BufferedReader.

./python -m timeit -s "l=[b'', b'a' * 10000]" "b''.join(l)"

before the patch:
100000 loops, best of 3: 2.35 usec per loop
after the patch:
1000000 loops, best of 3: 0.335 usec per loop

----------
components: Interpreter Core
files: bytesjoin.patch
keywords: patch
messages: 70365
nosy: pitrou
severity: normal
status: open
title: optimize bytes.join()
type: performance
versions: Python 3.0
Added file: http://bugs.python.org/file10999/bytesjoin.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3459>
_______________________________________


More information about the Python-bugs-list mailing list