Message166904
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. |
|
Date |
User |
Action |
Args |
2012-07-30 14:57:56 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, collinwinter, alex, hevi |
2012-07-30 14:57:56 | serhiy.storchaka | set | messageid: <1343660276.5.0.131364441511.issue15503@psf.upfronthosting.co.za> |
2012-07-30 14:57:55 | serhiy.storchaka | link | issue15503 messages |
2012-07-30 14:57:55 | serhiy.storchaka | create | |
|