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

Резултати

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

Пребарај: #globaluncertainty

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

@CryptoM · Post #64527 · 09.04.2026 г., 06:14

🚀 Japan Considers Additional Oil Reserve Release Amid Strait of Hormuz Uncertainty Japan is contemplating the release of an additional 20 days' worth of oil reserves as early as May. According to NS3.AI, this decision comes amid ongoing uncertainties surrounding the reopening of the Strait of Hormuz. Japan's heavy reliance on the Middle East for approximately 95% of its oil supply underscores the significance of this move. Since March 16, Japan has already released around 50 days of reserves and still maintains a reserve sufficient for 230 days. #Japan#oilreserves#StraitofHormuz#oilsupply#MiddleEast#energymarket#globaluncertainty

Crypto M - Crypto News

@CryptoM · Post #64775 · 09.04.2026 г., 22:03

🚀 PRECIOUS METALS | Spot Gold and Silver Open Slightly Higher, WTI Crude Oil Rises Spot gold and silver prices opened slightly higher on Friday, alongside an increase in WTI crude oil prices. According to Jin10, the futures for the three major U.S. stock indices showed a slight decline. This movement in the commodities market comes amid ongoing global economic uncertainties, influencing investor sentiment and market dynamics. The fluctuations in precious metals and crude oil prices are closely watched by traders and analysts, as they reflect broader trends in the financial markets. #preciousmetals#gold#silver#WTI#crudeoil#economy#commodities#globaluncertainty#financialmarkets#trading#investors

Crypto M - Crypto News

@CryptoM · Post #65042 · 10.04.2026 г., 15:27

🚀 Hermès Expands Leather-Goods Production Amid Global Uncertainty Hermès has inaugurated its 25th leather-goods manufacturing facility in France, continuing its strategy to boost production despite a slowdown in luxury demand. Bloomberg posted on X, highlighting the company's commitment to growth even as geopolitical tensions, such as the Iran conflict, introduce new uncertainties to the market. Hermès remains focused on expanding its operations, aiming to meet long-term goals despite current challenges in the luxury sector. #Hermès#LeatherGoods#Luxury#Manufacturing#France#Expansion#GlobalUncertainty#LuxuryMarket#BusinessGrowth#Geopolitics

Crypto M - Crypto News

@CryptoM · Post #64541 · 09.04.2026 г., 07:05

🚀 U.S. Dollar Index Remains Stable Amid Middle East Tensions The U.S. Dollar Index (DXY) maintained stability on April 9, despite ongoing uncertainties surrounding the conflict in Iran. According to BlockBeats, the situation remains tense following a two-week ceasefire agreement between the United States and Iran. Iran continues to launch missiles and drones towards Arab nations in the Persian Gulf, while Israel has targeted Hezbollah militants in Lebanon. Iran has also informed mediators of its intention to limit the number of ships passing through the Strait of Hormuz and impose transit fees. Analysts from Commerzbank have expressed concerns, suggesting that the ceasefire may be a fragile pause in the conflict, as it inherently implies further negotiations. #USDollarIndex#MiddleEastTensions#IranConflict#DXY#Ceasefire#StraitOfHormuz#PersianGulf#Israel#Hezbollah#Commerzbank#TransitFees#GlobalUncertainty