Skip to content

Instantly share code, notes, and snippets.

@keyz182
Created January 26, 2015 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyz182/8ecf17ff6bfac11e314c to your computer and use it in GitHub Desktop.
Save keyz182/8ecf17ff6bfac11e314c to your computer and use it in GitHub Desktop.
import string, random
from timeit import Timer
strs = []
for i in range(500):
strs.append(''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)))
def slow():
str = ''
for s in strs:
str +=s
def fast():
str = ''.join(strs)
t = Timer(lambda: slow())
print t.timeit(number=100000)
t = Timer(lambda: fast())
print t.timeit(number=100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment