[issue15503] concatenating string in dict unexpected performance

2012-07-30 Thread Antoine Pitrou
Antoine Pitrou added the comment: It's a FAQ entry: http://docs.python.org/dev/faq/programming.html#what-is-the-most-efficient-way-to-concatenate-many-strings-together -- nosy: +pitrou resolution: -> wont fix status: open -> closed ___ Python tracker

[issue15503] concatenating string in dict unexpected performance

2012-07-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yes, the total time of repeated string concatenation is O(N**2). s3 is twice larger s2, therefore s3 time about twice large s2 time. In the first case Python use a special optimization which allows O(N) in some cases. You can deactivate it: s5 = """ text =

[issue15503] concatenating string in dict unexpected performance

2012-07-30 Thread Alex Gaynor
Alex Gaynor added the comment: Actually, I would argue that it's concatentation of a local variable which has unexpected performance. Logically it should be O(n**2), however due to hacks in CPython it isn't. -- nosy: +alex ___ Python tracker

[issue15503] concatenating string in dict unexpected performance

2012-07-30 Thread Petri Heinilä
New submission from Petri Heinilä: In concatenating string in dict somehow radically depends the added string size. code import timeit s1 = """ text = "" for i in range(1,5): text += "12345678901234567890" """ print("str cat 20: {0}s".format(timeit.timeit(s1,number=1))) s2 = """ d