Created
January 23, 2020 06:15
-
-
Save paulwinex/47933e95cd537afba5d7d83c4395643f 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
from timeit import timeit | |
def t1(): | |
# складываем 10 строк через + из переменной | |
t = 'text' | |
for _ in range(1000): | |
s = t + t + t + t + t + t + t + t + t | |
def t2(): | |
# склеиваем список строк через метод join | |
arr = ['text'] * 10 | |
for _ in range(1000): | |
s = ''.join(arr) | |
def t3(): | |
# складываем через + но не из переменной а непосредственно инлайн объекты | |
for _ in range(1000): | |
s = 'text' + 'text' + 'text' + 'text' + 'text' + 'text' + 'text' + 'text' + 'text' + 'text' | |
print(timeit(t1, number=10000)) | |
print(timeit(t2, number=10000)) | |
print(timeit(t3, number=10000)) | |
def t4(): | |
t = 'text'*100 | |
for _ in range(1000): | |
s = t + t + t + t + t + t + t + t + t | |
def t5(): | |
arr = ['text'*100] * 10 | |
for _ in range(1000): | |
s = ''.join(arr) | |
def t6(): | |
for _ in range(1000): | |
s = 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 + 'text'*100 | |
print(timeit.timeit(t4, number=10000)) | |
print(timeit.timeit(t5, number=10000)) | |
print(timeit.timeit(t6, number=10000)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment