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

Резултати

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

Пребарај: #tensions

当前筛选 #tensions清除筛选
Crypto M - Crypto News

@CryptoM · Post #65353 · 13.04.2026 г., 02:04

🚀 Iranian Official Warns of Potential Response to U.S. Naval Blockade An Iranian official has issued a warning regarding Iran's potential response to a U.S. naval blockade. According to NS3.AI, the official indicated that Iran possesses an unused strategy that could be employed if tensions escalate further. This statement comes amid ongoing geopolitical tensions between the two nations, highlighting the complex dynamics at play in the region. #Iran#US#NavalBlockade#Geopolitics#Tensions#Strategy#MiddleEast

Crypto M - Crypto News

@CryptoM · Post #65095 · 11.04.2026 г., 00:45

🚀 Lebanon and Israel to Hold First Meeting on Ceasefire Talks Lebanon and Israel have agreed to hold their first meeting on Tuesday at the U.S. State Department to discuss a ceasefire and set a date for negotiations. According to BlockBeats, this development marks a significant step towards addressing ongoing tensions between the two nations. #Lebanon#Israel#Ceasefire#Negotiations#USStateDepartment#Tensions

Crypto M - Crypto News

@CryptoM · Post #65350 · 13.04.2026 г., 01:55

🚀 U.S. and Iran Maintain Temporary Ceasefire Amid Tensions U.S. President Donald Trump announced that the temporary two-week ceasefire between the United States and Iran is "generally holding well." According to Odaily, this statement comes despite the lack of progress in marathon negotiations held over the weekend in Pakistan. Trump, speaking to reporters upon his return to Washington from Florida, stated, "I think it's generally holding well. Their military has been destroyed. Their entire navy is at the bottom of the sea." He also mentioned that the U.S. would begin a blockade of the Strait of Hormuz at 10 a.m. Eastern Time on Monday. Additionally, Trump noted that two American soldiers rescued in Iran earlier this month are currently in good condition. #US#Iran#Ceasefire#Tensions#Trump#Military#Negotiations#StraitOfHormuz

Crypto M - Crypto News

@CryptoM · Post #65018 · 10.04.2026 г., 14:06

🚀 Iranian Military Maintains High Alert Amid U.S. and Israeli Tensions On April 10, the Iranian Armed Forces announced that they remain on high alert, ready to engage if necessary. According to BlockBeats, a spokesperson from the Khatam al-Anbiya Central Headquarters stated that this stance is due to repeated breaches of trust by the United States and Israel. The statement underscores ongoing tensions in the region, highlighting Iran's preparedness to respond to perceived threats. #Iran#Military#US#Israel#Tensions#MiddleEast#Alert

Crypto M - Crypto News

@CryptoM · Post #65401 · 13.04.2026 г., 05:15

🚀 U.S. to Impose Blockade on Iranian Ports Amid Tensions U.S. President Donald Trump announced on his social media platform that the United States will enforce a blockade on ships entering and exiting Iranian ports at 10 a.m. Eastern Time on April 13. According to BlockBeats, this decision follows unsuccessful negotiations between the United States and Iran. On April 12, President Trump expressed indifference towards Iran's willingness to return to the negotiating table. He reiterated the plan to impose the blockade and voiced disappointment over NATO's lack of support for the U.S. in the conflict involving Iran. #US#Iran#blockade#Trump#NATO#tensions#MiddleEast#sanctions#diplomacy

Crypto M - Crypto News

@CryptoM · Post #65141 · 11.04.2026 г., 11:36

🚀 Russia and Ukraine Conduct Prisoner Swap Mediated by UAE Russia and Ukraine have successfully exchanged 175 prisoners of war, with the United Arab Emirates playing a mediating role in the process. Bloomberg posted on X, highlighting the significance of this exchange amid ongoing tensions between the two nations. The swap marks a notable development in the efforts to address humanitarian concerns arising from the conflict. Both countries have been engaged in a prolonged conflict, and such exchanges are seen as steps towards easing tensions and addressing the humanitarian impact of the war. The involvement of the UAE underscores the international community's interest in facilitating dialogue and resolution between Russia and Ukraine. This exchange is part of ongoing efforts to manage the humanitarian aspects of the conflict, which has drawn widespread international attention. #Russia#Ukraine#PrisonerSwap#UAE#HumanitarianEfforts#ConflictResolution#InternationalDiplomacy#HumanitarianImpact#Tensions#War