Message373312
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. |
|
Date |
User |
Action |
Args |
2020-07-08 15:04:38 | remi.lapeyre | set | recipients:
+ remi.lapeyre, asvetlov, yselivanov, ys19991 |
2020-07-08 15:04:38 | remi.lapeyre | set | messageid: <1594220678.89.0.216196884246.issue41242@roundup.psfhosted.org> |
2020-07-08 15:04:38 | remi.lapeyre | link | issue41242 messages |
2020-07-08 15:04:38 | remi.lapeyre | create | |
|