Advertisement
here2share

# join_vs_concat_surprise.py

Apr 18th, 2021
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. # join_vs_concat_surprise.py
  2.  
  3. from time import clock
  4.  
  5. def timer(test):
  6.     ttt = clock()
  7.     exec(test)
  8.     print test
  9.     print "{:.8f}".format(clock()-ttt)
  10.     print  
  11.  
  12. limit = 10**6
  13.  
  14. def concat_str():
  15.     resp = ''
  16.     for num in xrange(limit):
  17.         resp += `num`
  18.     return resp
  19.  
  20. timer('''concat_str()''')
  21.  
  22. def join_list():
  23.     return ''.join([`num` for num in xrange(limit)])
  24.  
  25. timer('''join_list()''')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement