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

Резултати

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

Пребарај: #tondns

当前筛选 #tondns清除筛选

Why collect SBT and XP from🙏TON Society? Let us remind you that SBT (Soulbound Token) is an NFT that is tied to your wallet, it cannot be traded or sold, which makes your wallet unique if it stores SBT NFT. What is it for? SBT NFT is a kind of “identity confirmation”, but only anonymous. SBT makes it clear to the sender that he is dealing with the right recipient and the right person behind him. Including when it comes to awards for contributions to the development of The Open Network. Such rewards can be obtained for activities within the Open League, they are displayed in your TON Society profile. What will SBT and XP owners get? Already, many people are collecting these achievements expecting to receive a reward in the future, but few people know how it works and what they can count on. ❤️Open League and SBT • SBTs are issued (minted) by the TON Society for contributions to the development of the TON blockchain community - for example, for participating in competitions and attending AMA sessions, attending conferences and meetups. • SBTs are issued by projects that receive incentives and grants through the Open League. 🫰Experience Points (XP) will become reputation points and will be converted into $TON • XP points at a 1:1 ratio to $TON , can be exchanged for $TON at any time. • Time-based formula affects the exchange rate - if $XP tokens are redeemed before March 31, 2025, the conversion will be at a less favorable rate. • On March 31, 2025, 1 XP will be equal to 1 $TON • SBT assumes a constant increase in XP income for inviting friends, purchasing Telegram Premium or TON DNS. 🔝TON Society will become the new public profile of the TON member, recognizing and rewarding everyone's achievements and contributions. #TON#Toncoin#TheOpenLeague#MassAdoption#TONSociety#TONDNS#SBT#NFT ⚡️Boost | 🎞YouTube |🌐Twitter