Created
June 4, 2014 13:43
-
-
Save Veedrac/4f436a1c21cc79ec6303 to your computer and use it in GitHub Desktop.
This file contains 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
from timeit import Timer | |
from functools import partial | |
def add_string(n): | |
s = '' | |
for _ in range(n): | |
s += ' ' | |
def add_string_in_list(n): | |
l = [''] | |
for _ in range(n): | |
l[0] += ' ' | |
Timer(partial(add_string, 1000000)).timeit(1) | |
#>>> 0.1848409200028982 | |
Timer(partial(add_string, 10000000)).timeit(1) | |
#>>> 1.1123797750042286 | |
Timer(partial(add_string_in_list, 10000)).timeit(1) | |
#>>> 0.0033865350123960525 | |
Timer(partial(add_string_in_list, 100000)).timeit(1) | |
#>>> 0.25131178900483064 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment