This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jcon
Recipients benjamin.peterson, ezio.melotti, jcon, pitrou, vstinner
Date 2011-08-22.00:43:54
SpamBayes Score 5.081874e-07
Marked as misclassified No
Message-id <1313973836.25.0.316459845083.issue12805@psf.upfronthosting.co.za>
In-reply-to
Content
I noticed there are a few more common cases that can be sped up in bytes.join().

When:
 - The sequence length and separator length are both 0
 - The separator length is 0 or 1
 - The separator string contains only 1 distinct byte

These could also be applied to other sequence types.

for i in {{0..5}}; do
./python -m timeit -s "f=open('/usr/share/dict/words', 'rb'); L=f.readlines()" \
"b' '.join(L)"; 
done

- BEFORE -
100 loops, best of 3: 3.79 msec per loop
100 loops, best of 3: 3.5 msec per loop
100 loops, best of 3: 3.75 msec per loop
- AFTER -
100 loops, best of 3: 2.81 msec per loop
100 loops, best of 3: 2.81 msec per loop
100 loops, best of 3: 3.03 msec per loop

~20% speedup

Same test on a smaller list (lines from LICENSE file) yields a similar 15-20% speedup.
Same test on L = [b'1', b'2', b'3'] yields 10% speedup
History
Date User Action Args
2011-08-22 00:43:56jconsetrecipients: + jcon, pitrou, vstinner, benjamin.peterson, ezio.melotti
2011-08-22 00:43:56jconsetmessageid: <1313973836.25.0.316459845083.issue12805@psf.upfronthosting.co.za>
2011-08-22 00:43:55jconlinkissue12805 messages
2011-08-22 00:43:54jconcreate