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