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

Пребарај: #ncdcupdates

当前筛选 #ncdcupdates清除筛选

🚨#WellnessWednesday: Protect Yourself from Lassa Fever! 🚨 Lassa fever is still a public health threat in Nigeria, with 413 confirmed cases and 80 deaths reported so far in 2025. 🦠 Here’s how you can reduce your risk and stay safe: ✅ Store food properly – Keep food and grains in sealed containers to prevent rat contamination. ✅ Keep your home clean – Eliminate rodent hiding places by keeping your environment tidy. ✅ Practice good hand hygiene – Wash your hands regularly with soap and running water. ✅ Avoid bush burning – It drives rats into homes, increasing the risk of infection. ✅ Seek medical help early – If you experience fever, weakness, or bleeding, visit a health facility immediately. Lassa fever is preventable! Stay informed and take action to protect yourself and your loved ones. 📖 Read the full situation report here: https://ncdc.gov.ng/themes/common/files/sitreps/d84698b45d03dafb399e97fa8379c4d5.pdf #StaySafe#LassaFever#TakeResponsibility#NCDCUpdates

🚨 Meningitis is a life-threatening infection! 🚨 Early detection can save lives. Seek medical help immediately if you or a loved one experience: ⚠️ Neck pain & stiffness ⚠️ Sensitivity to bright lights ⚠️ Vomiting & nausea ⚠️ Muscle, joint, or limb pain ⚠️ Skin rash ⚠️ Seizures ⚠️ Cold hands & feet Don’t wait! Report to a healthcare facility immediately! #MeningitisAwareness#TakeResponsibility#StaySafe#NCDCUpdates

📢 DIPHTHERIA UPDATE | Epi-Week 06, 2025 🦠 New suspected cases: 35 🛑 New confirmed cases: 19 🙏 New deaths: 0 📍 Total cases so far: ⚠️ 41,978 suspected ✅ 25,298 confirmed 💔 1,279 deaths 📌 26 states & 184 LGAs affected 💡 What you should know: Diphtheria is highly contagious but preventable with vaccination! 💉 ✅ Get vaccinated ✅ Practice good hygiene ✅ Seek medical care early 📖 Full report here: 🔗ncdc.gov.ng/themes/common/files/sitreps/943ca4ce8c5adaa7a1f04f467804c84a.pdf #Diphtheria#PublicHealth#VaccinesWork#TakeResponsibility#NCDCUpdates

#WellnessWednesday: Boost Your Immunity, Stay Protected! 🛡️🥦 Your immune system is your first line of defense against infections, including Mpox and other diseases. Keep it strong with these healthy habits: 🥗 Eat a balanced diet rich in fruits, vegetables, and proteins 🚶‍♂️ Stay active with regular exercise 💧 Hydrate—drink plenty of water daily 😴 Get enough sleep to support immune function 🧼 Practice good hygiene—wash hands frequently and keep surroundings clean 💉 Stay up to date on vaccinations where applicable A strong immune system means a healthier you! Take charge of your wellness today. #WellnessWednesday#HealthyLiving#BoostYourImmunity#StayProtected#NCDCUpdates

#HealthTipMonday: Protect Yourself While Caring for Mpox Patients! 🏥🦠 Healthcare workers, your safety matters! Prevent Mpox infection by following standard Infection Prevention and Control (IPC) measures when handling suspected or confirmed cases. Your safety is just as important as your patients. Protect yourself while protecting others! Stay safe, stay informed. #HealthTipMonday#PreventMpox#InfectionControl#HealthcareSafety#NCDCUpdates