Message142650
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 |
|
Date |
User |
Action |
Args |
2011-08-22 00:43:56 | jcon | set | recipients:
+ jcon, pitrou, vstinner, benjamin.peterson, ezio.melotti |
2011-08-22 00:43:56 | jcon | set | messageid: <1313973836.25.0.316459845083.issue12805@psf.upfronthosting.co.za> |
2011-08-22 00:43:55 | jcon | link | issue12805 messages |
2011-08-22 00:43:54 | jcon | create | |
|