fork(2) 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. for i in range(n):
  17. s = "".join(lst)
  18. end = time.time()
  19. print("%d strings joined in %.3f seconds" % (n, end - start))
  20.  
  21.  
  22.  
  23. concat(3000000)
  24. join(3000000)
Success #stdin #stdout 1.6s 9984KB
stdin
Standard input is empty
stdout
3000000 strings concatenated in 0.681 seconds
3000000 strings joined in 0.885 seconds