Advertisement
Guest User

list vs. concatenate

a guest
Apr 11th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. from time import time
  2. class Timer:
  3. def start(self):
  4. self.starttime = time()
  5. def stop(self):
  6. print(time()-self.starttime)
  7.  
  8. def fat_catenate():
  9. s = ''
  10. for i in range(3000000):
  11. s += 'a'
  12.  
  13. def listomania():
  14. l = []
  15. for i in range(3000000):
  16. l.append('a')
  17. ''.join(l)
  18.  
  19. t1 = Timer()
  20. t2 = Timer()
  21.  
  22. t1.start()
  23. fat_catenate()
  24. t1.stop()
  25.  
  26. t2.start()
  27. listomania()
  28. t2.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement