fork download
  1. import time
  2.  
  3. def concat(reps):
  4. start = time.time()
  5. for i in range(reps):
  6. s = ""
  7. s += "Вася"
  8. s += "1"
  9. s += "2"
  10. return time.time() - start
  11.  
  12.  
  13. def join(reps):
  14. start = time.time()
  15. lst = ["Вася", "1", "2"]
  16. for i in range(reps):
  17. s = "".join(lst)
  18. return time.time() - start
  19.  
  20. reps = 2000000
  21.  
  22. print("%d join = %.6f" % (reps, join(reps)))
  23. print("%d concat = %.6f" % (reps, concat(reps) * 0.75))
Success #stdin #stdout 1.4s 9984KB
stdin
Standard input is empty
stdout
2000000 join = 0.586540
2000000 concat = 0.592885