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 pitrou
Recipients loewis, pitrou, rhettinger, terry.reedy
Date 2008-08-01.23:44:04
SpamBayes Score 2.2501818e-05
Marked as misclassified No
Message-id <1217634246.09.0.357922311854.issue3459@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2008-08-01 23:44:06pitrousetrecipients: + pitrou, loewis, rhettinger, terry.reedy
2008-08-01 23:44:06pitrousetmessageid: <1217634246.09.0.357922311854.issue3459@psf.upfronthosting.co.za>
2008-08-01 23:44:05pitroulinkissue3459 messages
2008-08-01 23:44:04pitroucreate