Trivial performance questions
Peter Hansen
peter at engcorp.com
Sat Oct 18 10:05:38 EDT 2003
Alex Martelli wrote:
>
> I would (more hesitantly) claim the same for ''.join vs += in putting
> "a few" strings together. If they're really just a few performance
> will not matter. But as soon as they're not so few it does suddenly
> matter A LOT. So, even though the effort may not be trivial in this
> case, I still think of this as "a good habit to pick up" to the point
> where it becomes automatic... but it's not _quite_ as clear-cut.
Agreed that it's not as clear-cut, the more so because the construct
is inherently less readable. (More line noise, so to speak.) There
are times when I'll consciously choose += for a couple of lines
(yes, where I subconsciously know performance won't matter) to ensure
readability of the code.
Nevertheless, your (snipped) point is valid, and I have certainly
tried to develop both the "is None" and the "''.join" habits for
my own work.
-Peter
More information about the Python-list
mailing list