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

Пребарај: #electricalgrid

当前筛选 #electricalgrid清除筛选
Venezuelanalysis

@venanalysis · Post #1732 · 30.08.2024 г., 12:20

[BREAKING] Venezuela is facing a nationwide blackout, with all 24 states affected since early this morning. Authorities are working to restore power, and buses have been deployed in Caracas as the subway system is down. Story developing. Full report here: https://shorturl.at/omBak #ElectricalGrid

Venezuelanalysis

@venanalysis · Post #2314 · 24.03.2026 г., 20:45

📰 NEWS | Venezuela: Rodríguez Announces Electricity Rationing Ahead of Heatwave, Drought Forecast Venezuela has introduced a 45-day electricity saving plan as authorities anticipate increased demand driven by extreme heat and drought conditions, according to Acting President Delcy Rodríguez. The government also confirmed plans to reform the electricity sector to allow private investment through joint ventures in generation and distribution, aiming to address long-standing infrastructure limitations. Recent outages and limited operational capacity, estimated at 12–14 GW out of 34 GW installed, highlight ongoing challenges in the national grid. Read the full report here 👉🏾https://shorturl.at/2SmsF #ElectricalGrid#Sanctions

Venezuelanalysis

@venanalysis · Post #1761 · 30.09.2024 г., 21:22

VA columnist Jessica Dos Santos describes a recent nationwide blackout in Venezuela and the memories from similar events in 2019. While the country returned to normal faster this time, questions about the state of the electrical infrastructure linger. Read the full column here 👉🏼https://shorturl.at/kFJlK #ElectricalGrid#TalesofResistance

Venezuelanalysis

@venanalysis · Post #1919 · 25.03.2025 г., 23:32

📰 NEWS | Venezuelan Gov’t Scales Down Public Sector Schedule in Electricity Rationing Measure The Venezuelan government has announced a six-week electricity rationing plan for state institutions, citing a climate emergency. Public offices will operate on alternating days with reduced hours (8 am-12:30 pm). Essential services remain unaffected. Western states, including Mérida, Táchira, Barinas, and Zulia, have faced daily blackouts of up to eight hours. Analysts point to drought-related hydroelectric challenges and concerns over the country’s transmission infrastructure. 🔗 Read the report here: https://venezuelanalysis.com/news/venezuelan-govt-scales-down-public-sector-schedule-in-electricity-rationing-measure/ #ElectricalGrid#PublicSector