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 remi.lapeyre
Recipients asvetlov, remi.lapeyre, ys19991, yselivanov
Date 2020-07-08.15:04:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594220678.89.0.216196884246.issue41242@roundup.psfhosted.org>
In-reply-to
Content
Hi Wansoo, using += instead of str.join() is less performant. Concatenating n strings with + will create and allocate n new strings will str.join() will carefully look ahead and allocate the correct amount of memory and do all concatenation at one:


➜  ~ python3 -m timeit -s 's = ""' 'for i in range(1_000_000): s += "foo\n"'
5 loops, best of 5: 107 msec per loop
➜  ~ python3 -m timeit -s 'l = ["foo"]*1_000_000' '"\n".join(l)'
20 loops, best of 5: 9.96 msec per loop


It's a common idiom that you will meet a lot in Python.
History
Date User Action Args
2020-07-08 15:04:38remi.lapeyresetrecipients: + remi.lapeyre, asvetlov, yselivanov, ys19991
2020-07-08 15:04:38remi.lapeyresetmessageid: <1594220678.89.0.216196884246.issue41242@roundup.psfhosted.org>
2020-07-08 15:04:38remi.lapeyrelinkissue41242 messages
2020-07-08 15:04:38remi.lapeyrecreate