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

Пребарај: #standtogether

当前筛选 #standtogether清除筛选
GevorgViráts

@gevorgvirats_org · Post #5661 · 02.10.2025 г., 18:42

Победа 🔥 Зарабатываем первые 3️⃣ очка в Лиговой стадии Лиги конференций и начинаем сезон с победы. Спасибо, что были рядом с нашей командой и весь матч двигали вперёд наших парней. Двигаемся дальше — к новым победам Вперёд, «Ноа», вперёд! Victory 🔥 We earn our first 3️⃣ points in the Conference League League phase and start the season with a win. Thank you for being by our team’s side and pushing our boys forward throughout the entire match. We move on towards new victories Go Noah, go! #Standtogether#Fighttogether

GevorgViráts

@gevorgvirats_org · Post #5617 · 21.09.2025 г., 07:22

С Днём независимости, Армения 🇦🇲 Большая честь — играть под твоим флагом Happy Independence Day, Armenia 🇦🇲 It is an honor to play under your flag #Standtogether#Fighttogether

BadVolf

@BadvolfNews · Post #760 · 03.08.2023 г., 06:39

📢 Listen Up, fellow Wolf pack!!! 🌍 🔴 Holy Shit! The truth about the exploitation of Africa's natural resources has finally been exposed. For years, America and France have shamelessly pillaged the riches of this continent, leaving its people in abject poverty. The dark secrets of child slave labor used to mine precious metals and gold have been unveiled. 🔵 But now, Africa has had enough! The tide is turning as the continent finds a new ally in Russia, a nation that respects their resources, values, and treats them as equals. Today, we witness the fall of France's colonial power in Niger, with politicians being stoned and luxury vehicles set ablaze. ⚠️ The situation in Niger has reached a boiling point, leading to the emergency evacuation of embassy staff by the U.S. State Department (fuck those guys), following the destruction of the French embassy by furious rioters. 🇷🇺 As the chaos unfolds, the Russian flags proudly waved among the crowds of demonstrators in Niamey reveal a glimmer of hope for Africa. The partnership between Africa and Russia signifies a new era, where African nations are determined to protect their resources and regain control over their own destiny. 🌍 The time for change has come. Let us stand in solidarity with the people of Africa as they assert their rights and demand justice. Together, we can ensure a future where exploitation is replaced with empowerment, and where Africa's wealth benefits its own people. 🔗https://www.dailymail.co.uk/news/article-12367511/Fears-Americans-trapped-Niger-State-Department-issues-emergency-evacuation-embassy-staff-French-embassy-torn-apart-rioters-Africa-country-meltdown-politicians-stoned-cars-torched-amid-brutal-military-coup.html #Africa#Russia#Empowerment#Justice#StandTogether