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

Резултати

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

Пребарај: #lebanonunderattack

当前筛选 #lebanonunderattack清除筛选
Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3562 · 29.10.2024 г., 09:03

A map of the Israeli Airstrikes on the Lebanese Beqaa region that took the lives of 63 civilians and i jured more than 100 people in a raid of more than 100 airstrikes targeting the region. #LebanonUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3578 · 02.11.2024 г., 09:17

#Israel carried out a large-scale massacre today, November 1, 2024, in the Lebanese towns of Baalbek district. 52 people were killed, 72 wounded, and 9 remain missing after 25 airstrikes by Israeli warplanes conducted over two hours, from 2 p.m. to 4 p.m. #LebanonUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3557 · 27.10.2024 г., 18:20

Even in the darkest times of #war, humor becomes a tool for resilience, offering brief moments of relief and a way to cope with the harsh realities. It’s a reminder that laughter, no matter how fleeting, can be a powerful act of defiance and hope in the face of adversity. #LebanonUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3555 · 27.10.2024 г., 08:53

The Lebanese Ministry of Health's Emergency Operations Center reported that the death toll from the Israeli assault has climbed to 2,653, with 12,360 others wounded since October 8, 2023. This staggering rise reflects the continuous bombardment and escalating violence. #Israel#Lebanon#LebanonUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3656 · 17.11.2024 г., 18:14

Israel has struck Beirut once again, this time targeting Mar Elias Street; the heart of the capital and one of its most densely populated areas during the war, as countless displaced families from the suburbs have sought refuge there. This relentless aggression is not just an attack on civilians; it’s a blatant violation of all norms of international law, crossing every red line. #LebanonUnderAttack #BeirutUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3463 · 14.10.2024 г., 12:27

Zionist Israeli Psychopaths hit a home in Ayto town in #Zgharta north #Lebanon that was housing families displaced from South Lebanon and Beirut suburbs. 25 humans in the house, the Red cross so far said that 18 are martyred. I will not share any videos or photos, as many of the women might be hijabis, and the footage shows them in heartbreaking scenes without their hijabs. #LebanonUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3657 · 18.11.2024 г., 08:45

Devastation in the heart of Beirut: On the night of November 17, #Israel targeted a densely populated building on the famous Mar Elias Street, setting off a massive fire that raged through the night. The building housed motor generators and an electronics shop, where lithium batteries likely fueled the inferno, adding to the chaos and destruction. #LebanonUnderAttack#WarCrimes#Beirut

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #4023 · 18.02.2025 г., 13:17

Ophthalmologist MP Elias Jradeh reveals that a blockade was imposed on Lebanon regarding the import of corneas after the Pagers bombing, which led to their disappearance from the local market and harmed various Lebanese citizens. #Lebanon#PagersAttack#Hezbollah#LebanonUnderAttack

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3586 · 04.11.2024 г., 17:01

In a heartbreaking video, Julia shared moments while she was playing the piano in her home in Khiam, South Lebanon, which she discovered in a video circulated by Israeli soldiers that was destroyed during the border clashes when they were attempting to occupy her town. #SouthLebanon#Khiam#LebanonUnderAttack#Israel

12
ПретходнаСтраница 1 од 2Следна