Created
January 26, 2015 17:14
-
-
Save keyz182/8ecf17ff6bfac11e314c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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