[issue28004] Optimize bytes.join(sequence)

Serhiy Storchaka report at bugs.python.org
Sat Sep 10 05:39:50 EDT 2016


Serhiy Storchaka added the comment:

Tests in the article don't look reliable. For example bytes_percent() and bytes_plus() test nothing, because b"%s %s" % (b"hi", b"there") and b"hi" + b" " + b"there" are evaluated at compile time.

Yes, bytes.join(sequence) is a little slower on Python 3 for short sequences. But for long sequences Python 3 is faster.

The code for bytes.join() is already too complex, and the proposed optimization makes it more complicated. And the optimization decreases performance on my netbook:

$ ./python -m timeit -s "sep=b' '; seq=(b'hello', b'world')" -- 'sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq); sep.join(seq)'

Python 2.7: 100000 loops, best of 3: 7.24 usec per loop
Python 3.6 unpatched: 100000 loops, best of 3: 8.62 usec per loop
Python 3.6 patched: 100000 loops, best of 3: 9.11 usec per loop

----------

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


More information about the Python-bugs-list mailing list