here2share

# join_vs_concat_surprise.py

Apr 18th, 2021
588
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()''')
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×