TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #32 · 7 фев.

Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять: 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' + ... # всего 10 раз Теперь каждую строку склейки запустим по 10М раз >>> timeit(t1, number=10000) 0.21951690399964718 >>> timeit(t2, number=10000) 1.4978306379998685 >>> timeit(t3, number=10000) 0.2213820789993406 Хм, а нам говорили что через "+" это плохо и медленно ))) 😁 Тут стоит учитывать, что речь идёт о склейке множества длинных строк. Давайте изменим условия: 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 + ... # всего 10 раз >>> timeit(t4, number=10000) 12.795130728000004 >>> timeit(t5, number=10000) 2.642637542999182 >>> timeit(t6, number=10000) 0.2184546610005782 Вот, уже другой разговор, сразу видна разница, в среднем в 6 раз. Но погодите, почему последний тест t6() по скорости такой же как и t3()? Ведь строки теперь в 100 раз длиннее! Это вопросы оптимизации кода, какие простые изменения ускоряют или замедляют выполнение программы. Мы столкнулись с примером обхода обращения к переменной. Например, именно так работает директива #define в С++, во время компиляции подставляя значение переменной вместо ссылки на неё. В Python это тоже работает, но часто ли вы сможете встретить такой способ работы со строками? К сожалению, способ почти только теоретический. В целом, тесты показали то, что мы хотели. Делаем выводы самостоятельно. Полный листинг 🌍 #tricks

Резултати

Пронајдени 3 слични објави

Пребарај: #contents

当前筛选 #contents清除筛选
Quiet World 🍁

@QuietWorld · Post #6661 · 07.10.2019 г., 13:00

Sometimes, I scrolled back to my previous #thoughts posts so that I can reread and remember what I said to myself to calm myself down & to assure that I can cope, so that I can cope again & again & again – & this is the main reason I started this channel last year & I'm glad I did, although I started to quite neglect it a lot this year 🥺 & I'm thankful for those of you who subscribed and stayed in this channel, especially those who responded to my #poll, interacted with us through our @qw_qwbot, & view our posts, because tbh it makes me feel like there's someone 'listening' to me and that is enough and much appreciated ❤ Thanks dear subscribers. Anyway, just for the update, we only have two admins now; Conan & me, but Conan seems to be occupied with his work since he started working this year, so because of those two reasons mentioned earlier, there might be less frequent posts in this channel 😅 But worry not, because we'll still be providing you with the best #contents we can 🤗 As for the new subscribers, welcome! 🥰🥳 #channelupdate#chupdate @quietworld🍃

Tg Links

@TgDict · Post #9 · 09.03.2021 г., 11:27

#Start#contents#index#mark This channel publishes groups and channels according to a main directory and several subject sub-directories for index search The search keywords are as follows: One type of keywords: Nine categories of first-level keywords Two types of keywords: Second-level keywords + geographic region + language family 1. Telegraph #telegram#Promotion #Group#channel#robot #Search#index#navigation 2. Resources #Resources#Share #Sharing#Welfare#moive#music#Books 3. Broadcasting #Broadcasting #message#info#news#blog 4. Chat category #Chat #chitchat#communication#city#area #Chinese#English#language#country #Mainland#HongKong#Taiwan 5. Computer category #Computer #Hardware#software#VPN#programming 6. Life category #life #Entertainment#Game#Funny#Anime #Live#tourism 7. Subjects #Subjects #Interest#hobbies#topic 8.Industry #Industry#business 9.To be classified #notes Unclassified