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 слични објави

Пребарај: #ageofmars

当前筛选 #ageofmars清除筛选

💵 How to make money in the P2E game Age of Mars? 💵 AGE OF MARS is a 3D game in which you conquer Mars. You will need to produce water, oxygen, and rocket fuel to trade these resources for real money How it works 👇 1️⃣ Buy Aqua NFT and (or) Planta NFT of any rarity - from common to legendary. The higher the rarity of an NFT, the greater its profitability. 2️⃣ Place your NFTs on the playing field. They will become in-game assets and will generate daily resources that can be exchanged for MRT tokens. This token is traded on the Pancake Swap exchange as MRT/USDT pair, which means you can instantly top-up your USDT wallet. 3️⃣ Increase your income - upgrade your NFTs to level 10. Yield at Level 10 can be 101% higher than at Level 1. 4️⃣ Try minting - create a new NFT from two existing ones. Minting is available for Level 10 tokens. You can play together with your team members and earn passive income - up to 15% from NFT sales and up to 80% from all resources generated in your team. 💰How to start earning 💰 ➡️Register using the link ➡️ Top up your balance ➡️ Buy NFTs on the marketplace ➡️ Place them on the in-game map ➡️ Collect resources and exchange them for USDT REGISTRATION | TELEGRAM CHANNEL #P2E#Play2Earn#AgeOfMars

​​🎙TOP TIER PROJECT ANNOUNCEMENT 🔥🔥🔥 👉Age of Mars - a P2E game. Make money on the colonization of Mars 💵👽💵 📌A whole new generation of P2E games is coming: they offer a free 2 play model, high-quality graphics, addictive gameplay, and a sustainable economic model. It is a fully-fledged 3D game in which you are required to turn Mars into a habitable planet. 📌The spaceship will take you to Mars, where your mission will be to create a habitable planet. You will get to develop your base and extract liquid resources that can be instantly converted into MRT utility tokens (MRT 👉 USDT). 👩‍🚀 Level up your NFTs and earn more. Depending on the rarity of the NFT, the yield on level 10 can be 101% higher than on level 1. In addition, level 10 unlocks Minting, the process of creating a new NFT at the expense of two NFTs you already own. 🧨 Age of Mars has a dedicated game mode for teams. You can earn up to 15% from NFT sales and up to 80% of the resources generated in your team. These are the best rewards across all blockchain games! 🤌 👉You can join the conquest of Mars by following the link.🔥🔥🔥 REGISTRATION| Telegram #P2E#Play2Earn#AgeOfMars