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

Резултати

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

Пребарај: #hotcross

当前筛选 #hotcross清除筛选
Airdrop3 LTD

@airdrop3ltd · Post #325 · 14.02.2022 г., 07:09

🎉 Celebrating the upcoming IHO of @RankerDAO on Hot Cross with a sweet giveaway! 🎁 $10,000 in #HOTCROSS 🎮 $10,000 in $RANKER 🏆 500 Winners ($40 each)! To join the campaign, do the following: 🐷 Follow @hotcrossann & https://t.me/RankerDAO_ann Announcements 🐷 Join @hotcross & @RankerDAO TG Group 🐷 Follow https://twitter.com/hotcrosscom & https://twitter.com/RankerDAO?t=chy4IrKNI1nJpvz58lTjxA&s=09 on Twitter 🤞Mandatory task ♻️ + ❤️ = RT + Like Fill the form below 👇🏼👇🏼👇🏼 https://t.co/SBRaDgUu5i #airdrophttps://t.co/OdpjOYVT7v

Airdrop3 LTD

@airdrop3ltd · Post #214 · 15.09.2021 г., 13:35

🎂 We would like to wish our friends at @FrontierDotXYZ a happy 1-year anniversary for $FRONT! 🎁#Giveaway time! Woohoo! 🏆 Download the Frontier Crypto & DeFi Mobile App to receive your share of $10,000 in #HOTCROSS 🎁 To join the campaign, do the following: 🐷 Follow @hotcrossann Announcements 🐷 Join @hotcross TG Group 🐷 Follow https://twitter.com/hotcrosscom on Twitter 🔷 Follow https://twitter.com/frontierdotxyz on Twitter 🔷Follow @FrontierDotXYZ Announcements. ♻️ Retweet the event on Twitter: Finally: 📨 Fill in the Gleam form for a chance to win! https://t.co/VN0d12SIXGhttps://t.co/bUrhZX7I3n Good luck 🤞.

Airdrop3 LTD

@airdrop3ltd · Post #184 · 25.08.2021 г., 11:03

🎊 Hot Cross hops into The Metaverse with SecondLive and an out of this world Blind Box Campaign! 🎂 To celebrate the 1-Year Anniversary of #BinanceSmartChain@bsc_official_announcement we are teaming up with @SecondLiveCommunity to give away Limited Edition #HOTCROSS blind boxes and mine $HOTCROSS during the festival. 🎁 To join the campaign, do the following: 🐷 Follow @hotcrossann Announcements 🐷 Join @hotcross TG Group 🐷 Follow Hot Cross on Twitter 🔷 Follow SecondLive on Twitter 🔷 Join @SecondLiveCommunity TG Group ♻️ Retweet the event on Twitter: https://twitter.com/hotcrosscom/status/1430478918423748613 Finally: 📨 Fill in the Gleam form for a chance to win! https://hotcross.link/secondlive Good luck to all in the Metaverse and Happy Anniversary to Binance Smart Chain!

Airdrop3 LTD

@airdrop3ltd · Post #270 · 15.11.2021 г., 17:14

🎂 Celebrating the Second hotcross IHO on #binancesmartchain. 🎁#Giveaway time! Woohoo! 20000$ in #Hotcross + $PEL for 1000 winners. 🎁 To join the campaign, do the following: 🐷 Follow @hotcrossann Announcements 🐷 Join @hotcross TG Group 🐷 Follow https://twitter.com/hotcrosscom on Twitter 🔷 Follow https://twitter.com/propelxyz 🔷Follow https://t.me/propelchat 🎆 Follow. https://t.me/propel_ann ♻️ Retweet the event on Twitter: Finally: 📨 Fill in the Gleam form for a chance to win! https://gleam.io/PJO9K/the-hot-cross-x-propel-iho-giveaway Good luck 🤞.

Airdrop3 LTD

@airdrop3ltd · Post #242 · 18.10.2021 г., 17:26

🎂 Celebrating the first ever hotcross IHO on #binancesmartchain. 🎁#Giveaway time! Woohoo! 20000$ in #Hotcross + $toon 🎁 To join the campaign, do the following: 🐷 Follow @hotcrossann Announcements 🐷 Join @hotcross TG Group 🐷 Follow https://twitter.com/hotcrosscom on Twitter 🔷 Follow https://twitter.com/PontoonFi 🔷Follow https://t.me/pontoon_fi group ♻️ Retweet the event on Twitter: ☠☠Read article for more info - https://updates.hotcross.com/p/iho-pontoon-finance Finally: 📨 Fill in the Gleam form for a chance to win! https://gleam.io/tGZd0/the-hot-cross-x-pontoon-iho-giveaway Good luck 🤞.