fork download
  1. import time
  2.  
  3. def plusravno(copies):
  4. start = time.time()
  5. l = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz0'] * copies
  6. s = ""
  7. for e in l:
  8. s += e
  9. end = time.time()
  10. print("%d strings concatenated in %.3f seconds" % (len(l), end - start))
  11.  
  12. def tochkajoin(copies):
  13. start = time.time()
  14. l = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqr', 'stu', 'vwx', 'yz0'] * copies
  15. s = ''.join(l)
  16. end = time.time()
  17. print("%d strings joined in %.3f seconds" % (len(l), end - start))
  18.  
  19. plusravno(1000000)
  20. tochkajoin(1000000)
Success #stdin #stdout 1.87s 9984KB
stdin
Standard input is empty
stdout
9000000 strings concatenated in 1.547 seconds
9000000 strings joined in 0.267 seconds