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 = "" for i in range(1,50000): text2 = text text += "12345678901234567890" """ print("str cat 20: {0}s".format(timeit.timeit(s5,number=1))) It's not a bug, it's feature. ---------- nosy: +storchaka _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15503> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com