Message70607
bl = [b'', b'a'] gives a 20% speedup:
before patch:
1000000 loops, best of 3: 0.443 usec per loop
after patch:
1000000 loops, best of 3: 0.349 usec per loop
(20% speedup)
bl = [b'a']*2 gives a 2% slowdown:
before patch:
1000000 loops, best of 3: 0.439 usec per loop
after patch:
1000000 loops, best of 3: 0.447 usec per loop
bl = [b'a']*10000 gives a 1% slowdown:
before patch:
1000 loops, best of 3: 510 usec per loop
after patch:
1000 loops, best of 3: 515 usec per loop
So, even in the worst case of joining the shortest possible non-empty
strings, the overhead is still minimal.
> Could not the .join user simply not add empty list items?
The .join user could also detect whether there is a single element in
the list and the separator is empty, and then avoid calling join :)
The point of integrating the optimization in bytes.join is that:
1) it makes it implicit, so that user code stays clean of "performance
hacks"
2) the optimization itself has much less overhead, since it is written
in C rather than in Python |
|
Date |
User |
Action |
Args |
2008-08-01 23:44:06 | pitrou | set | recipients:
+ pitrou, loewis, rhettinger, terry.reedy |
2008-08-01 23:44:06 | pitrou | set | messageid: <1217634246.09.0.357922311854.issue3459@psf.upfronthosting.co.za> |
2008-08-01 23:44:05 | pitrou | link | issue3459 messages |
2008-08-01 23:44:04 | pitrou | create | |
|