Antoine Pitrou <[EMAIL PROTECTED]> added the comment: 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 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3459> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com