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 serhiy.storchaka
Recipients alex, collinwinter, hevi, serhiy.storchaka
Date 2012-07-30.14:57:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1343660276.5.0.131364441511.issue15503@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-07-30 14:57:56serhiy.storchakasetrecipients: + serhiy.storchaka, collinwinter, alex, hevi
2012-07-30 14:57:56serhiy.storchakasetmessageid: <1343660276.5.0.131364441511.issue15503@psf.upfronthosting.co.za>
2012-07-30 14:57:55serhiy.storchakalinkissue15503 messages
2012-07-30 14:57:55serhiy.storchakacreate