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