import time
def concat(reps):
start = time.time()
for i in range(reps):
s = ""
s += "Вася"
s += "1"
s += "2"
return time.time() - start
def join(reps):
start = time.time()
lst = ["Вася", "1", "2"]
for i in range(reps):
s = "".join(lst)
return time.time() - start
reps = 2000000
print("%d join = %.6f" % (reps, join(reps)))
print("%d concat = %.6f" % (reps, concat(reps) * 0.75))
aW1wb3J0IHRpbWUKIApkZWYgY29uY2F0KHJlcHMpOgoJc3RhcnQgPSB0aW1lLnRpbWUoKQoJZm9yIGkgaW4gcmFuZ2UocmVwcyk6CgkJcyA9ICIiCgkJcyArPSAi0JLQsNGB0Y8iCgkJcyArPSAiMSIKCQlzICs9ICIyIgoJcmV0dXJuIHRpbWUudGltZSgpIC0gc3RhcnQKIAogCmRlZiBqb2luKHJlcHMpOgoJc3RhcnQgPSB0aW1lLnRpbWUoKQoJbHN0ID0gWyLQktCw0YHRjyIsICIxIiwgIjIiXQoJZm9yIGkgaW4gcmFuZ2UocmVwcyk6CgkJcyA9ICIiLmpvaW4obHN0KQoJcmV0dXJuIHRpbWUudGltZSgpIC0gc3RhcnQKIApyZXBzID0gMjAwMDAwMAoKcHJpbnQoIiVkIGpvaW4gPSAlLjZmIiAlIChyZXBzLCBqb2luKHJlcHMpKSkKcHJpbnQoIiVkIGNvbmNhdCA9ICUuNmYiICUgKHJlcHMsIGNvbmNhdChyZXBzKSAqIDAuNzUpKQ==