fork(1) download
  1. import time
  2. lst = ["Вася", "1"]
  3.  
  4.  
  5. def concat(n):
  6. start = time.time()
  7. s = ""
  8. for i in range(n):
  9. s += "Вася" + "1"
  10. end = time.time()
  11. print("%d strings concatenated in %.3f seconds" % (n, end - start))
  12.  
  13.  
  14. def join(n):
  15. start = time.time()
  16. s = "".join(lst * n)
  17. end = time.time()
  18. print("%d strings joined in %.3f seconds" % (n, end - start))
  19.  
  20.  
  21.  
  22. concat(3000000)
  23. join(3000000)
Success #stdin #stdout 0.93s 10016KB
stdin
Standard input is empty
stdout
3000000 strings concatenated in 0.651 seconds
3000000 strings joined in 0.250 seconds