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

Пребарај: #theparallel

当前筛选 #theparallel清除筛选

🎙Long waited testnet for Parallel is ON🔥🔥🔥 🎮TESTNET FOUNDATION GAME: PARAGON CRAFTING🎮 ➧REGISTER NOW! ⚖️Requirement: Have at least 1000 PRL in Wallet BUY NOW: https://poocoin.app/tokens/0xd07e82440a395f3f3551b42da9210cd1ef4f8b24 👉Registration Form: https://prl.onl/testnetform ⏰Registration Open: Jan 6, 2022 - Jan 10, 2022 ⏰Valid Wallet Scan: 13:00 UTC on Jan 10, 2022 #TheParallel#Metaverse#PRL

🔥🔥🔥ARE YOU READY? JUST 20 minutes LEFT There is nothing more excited than waiting for the Super Listing Event from The Parallel at the moment. Do not miss us! Set your alarm at 13:00 UTC right now, Parallese. Events on the Super Listing Event you should pay attention!! 👉 SQuizz Game on Livestream 🎁 20,000 PRL for the 200 people have the highest score Step 1: Log in to your MetaMask wallet address at theparallel.io Step 2: Follow the Super Listing event and wait for the questions to appear randomly throughout event time (15 questions in total) Step 3: Answer the questions at theparallel.io 👉 Share NOW - Earn NOW - 🎁 20,000 PRL for 1,000 fastest Parallese sharing and $1000 for 1 luckiest one Step 1: Share the Livestream on Facebook or Twitter with the hashtag #TheParallel#Super_Listing_Event#Metaverse#PRL Step 2: Tag 5 of your friends in the comment section Step 3: Enter the link of your sharing post and your wallet address at: https://t.me/prlsharenowbot 📌 Listing time: Revealed in the Livestream. You must watch the full live stream to find out 🔐 PRL smart contract address: 0xd07e82440A395f3F3551b42dA9210CD1Ef4f8B24 1️⃣ Install BEP-20 Wallet (Metamask) 2️⃣ Adding PRL smart contract before Listing will help shorten transaction time and increase fair competition with bots. 3️⃣ Prepare BUSD, BNB in your wallet and approve BUSD in PancakeSwap 📎 Find out details at: https://prl.onl/3FqvCrh

🎙The Parallel - An Infinite Metaverse announcement🔥🔥 The Parallel - An Infinite Metaverse@theparallel_io Feb 23👑 Check Out Rune Hunter: Ascension! First game launched by The Parallel Metaverse 👉Read the game guide! We want your first impressions and thoughts! 👉Checkout Ascension NOW:https://prl.onl/3LU3xfv ⏰ ETA: Mid March Testnet #Gamefi#playtoearn$PRL #PRL#theparallel#Ascension