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

Резултати

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

Пребарај: #usnews

当前筛选 #usnews清除筛选
America 🇺🇸 News & Politics

@America · Post #10645 · 13.05.2026 г., 13:05

⛽💸GAS PRICES HIT HIGHEST LEVEL OF THE YEAR AMID IRAN WAR 🔹 National average now exceeds four dollars fifty cents per gallon after fifty percent surge 📈 🔹 California tops six dollars per gallon — highest in the nation as supply tightens 💰 🔹 Six states including Alaska Hawaii Oregon near five dollar per gallon threshold 🗺️ 🔹 Airline fuel costs force Spirit Airlines shutdown and widespread fare increases ✈️ Americans paying the price for Middle East conflict — when will relief come? 😤⛽ #USNews#economy 🌍 This affects more people than you think 📲 🔥 Share this with someone who needs to know 📲 @america

America 🇺🇸 News & Politics

@America · Post #10640 · 12.05.2026 г., 13:04

⛽🇺🇸TRUMP PLEDGES FEDERAL GAS TAX SUSPENSION AS PRICES HIT 4-YEAR HIGH 🔹 National average reaches $4.52/gallon - up from $3.14 just one year ago 📊💸 🔹 18.4¢ federal tax suspension could provide immediate relief while Congress approves 🏛️✅ 🔹 Iran war drives oil surge as $500M weekly tax revenue faces temporary pause ⛽🚫 🔹 GOP lawmakers rush bills through House and Senate for quick implementation 📋⚡ 🔹 Big Oil companies bank $30M hourly in war windfall profits while families struggle 💰😡 "When gas goes down, we'll phase it back in" - Trump promises targeted relief! 🎯 Americans deserve affordable energy, not war profiteering! 🇺🇸💪 #USNews#economy @america

America 🇺🇸 News & Politics

@America · Post #10609 · 06.05.2026 г., 13:06

📊🇺🇸US JOBS MARKET HITS "STALL SPEED" — MARCH GAINS DISAPPOINT, UNEMPLOYMENT STUCK AT 4.3% 🔹 Alarming 12-month trend: Only two hundred sixty thousand total jobs added — averaging twenty-one thousand monthly 📉 🔹 Manufacturing sector DOWN seventy-one thousand jobs since April 2025 despite Trump tariff promises 🏭 🔹 Education gap explodes: 5.9% jobless rate for high school dropouts vs 2.8% for college graduates 🎓 🔹 Young workers brutalized: Ages 25-34 face 4.8% unemployment vs 35-44 demographic at just 3.2% rate 👥 Fed warns unemployment could peak at 4.5% — "brutal" job market ahead for 2026 college graduates! 💼😰 #USNews#economy @america

123•••10•••20•••2223
ПретходнаСтраница 1 од 23Следна