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

Пребарај: #dobroye

当前筛选 #dobroye清除筛选
DruschbaFM - English

@druschbaFm_en · Post #51966 · 12.03.2025 г., 08:02

⚡️🇷🇺🇺🇦⚡️ Two Majors #Summary for the Morning of 12 March 2025; 06:27 (GMT+3)⚡️ 🔹 The Russian Army continues its #Kursk offensive with decisive objectives. Yesterday, #KazachyaLoknya, #Zamostye, #Makhnovka, #Mirny, #Bondarevka, #Dmitryukov, and #Knyazhy1st and #Knyazhy2nd hamlets were liberated. Russian forces are advancing from #Sudzha’s industrial zone and central market, with reports of movement in the built-up areas. Footage has emerged of Ukrainian infantry retreating westward. Russian troops are also active in the #Sumy region near #Zhuravka. The #Sudzha – #Yunakovka Motorway is under Russian fire control, and AFU reinforcements attempting to enter the #Kursk region have been repelled. Heavy battles for the region’s liberation continue. 🎯 Russian Forces struck targets in #Odessa region overnight, with the enemy claiming a 'cargo ship carrying grain' was damaged. Confirmed strikes hit infrastructure in #Dnepropetrovsk, with explosions reported in #Kiev, #Pavlograd, #Kramatorsk, #SnakeIsland, as well as in the #Cherkassy, #Kharkov, #Sumy, and #Khmelnitsky regions. 🛡 Russian Air Defences repelled a night-time attack on the #Bryansk region. 🔹 In #Seversk Sector, Russian forces continue difficult advances west of #Belogorovka, facing fierce and organised 👉resistance. 🔹 In #Toretsk, reports persist of AFU units being deployed deeper into urban areas. 🔹 In #Pokrovsk Direction, clashes continue in #Shevchenko, #Peschanoye, #Kotlino, and #Uspenovka. On the far right flank, east of #Pokrovsk, Russian forces are attacking near #Tarasovka. 🔹 On the #Vremyevka Ledge, north of #VelikayaNovosyolka, the 'East Group of Troops' has secured #Dneprenergiya. The enemy claims successful counterattacks in #Novosyolka. 🔹 On the #Zaporozhye Front, Russian forces raised the flag over #Pyatikhatki after prolonged heavy battles.🎬👆The village, situated in a low-lying area, has been in ruins since summer 2023 and lacks underground shelters, making long term consolidation uncertain. 💥 In #Belgorod Region, the AFU continues to target civilians. In Shebekino district, a UAV attack damaged equipment at a commercial facility in #Dobroye. In #Shamino, an FPV drone struck a civilian car. Another drone hit a private residence in #NizhneyeBeryozovo2nd. In Grayvoron district, a UAV detonation in a private residence in #Glotovo caused an attic fire. In #Valuyki, an FPV drone damaged a car and shattered windows. In #Shelayevo, a drone exploded on the ground. 💥 In the #DPR, a 2001-born woman was injured in #Gorlovka following a Nazi artillery strike, with further damage to civilian infrastructure. In #KrasnayaPolyana, Volnovakha district, a 1966-born man sustained injuries from an explosive device detonation. 💬Welcome to Military Chat; 🇬🇧Battle Maps 📱 Join GLOBAL DEPTH to boost your TG Feed GLOBAL DEPTH from #HK This channel aims to unite interested individuals from around the world in an attempt to connect the dots. Subscriber participation is always welcome here and in the channel's Chat Group.