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

Резултати

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

Пребарај: #jvault

当前筛选 #jvault清除筛选

SettleTON v2.0 Major Release, WEB3 Collaboration, and instructions how to get SBT 🔄 The "v2.0" trend continues — after the recent Ston.Fi v2.0 update, we have the SettleTON project next in line. Below, we'll look at what's been added and updated in the new version: ➖ Improved MID-Risk index: Critical errors were fixed, increasing protocol stability. New #MetaVault system, which optimizes asset storage and makes the reinvestment process more efficient. ➖ Improved reliability: All asset contracts (vaults) now use their own database and infrastructure😊#SettleTON, therefore the balance and quality of reinvestment increases. ➖ A new section has appeared in the bot, in which you can earn RewardPoints (RP) for completing missions from SettleTON and their partners. 🫡SettleTON x WEB3 partnership and increased farming rewards: Team #WEB3 gave a good boost to their pool, you can see and touch it in the bot , in the "Vaults" tab. Also, soon Ston.fi pools will appear in SettleTON (ST), in their post they described the advantages of ST compared to direct deposits through #DEX. 🙏#SBT Hunting, featuring SettleTON: The popular staking project #JVault has launched a campaign in connection with the resumption of The Open League. For simple actions in Quest Bot and DeFi projects — providing liquidity, staking, swaps, subscribing to a channel, we have the opportunity to get an exclusive SBT. Plus, for all these shenanigans, we get additional points and rise in the #OpenLeague ranking, and then 🍔#TON itself. SettleTON | GitBook | Chat EN | X

SettleTon and Portfel Collaboration 🔥SettleTon has recently partnered with #TorchFinance, this time by adding a new project to the list – #Portfel. 💼 Portfel's goal is to become the main application for tracking our assets: all tokens, staking on multiple #DEX, provided liquidity, rewards, and using all the necessary #DeFi applications. The team shared their immediate plans and roadmap: 🟡#NFTs and their valuation 🟡Support for multiple addresses 🟡Staking platforms - #Tonstakers and #jVault 🟡Vaults by Storm.tg 🟡Token swaps via the best Dex Aggregator 🟡Token details page 🪅DeFiLlama also included#SettleTon on their platform, adding transparency and value for users. SettleTON | GitBook | Chat EN | X