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

Пребарај: #john

当前筛选 #john清除筛选
Pensive|

@PensivePost · Post #4777 · 20.01.2021 г., 14:26

*FRACTION OF SECONDS* Woke up. I knew I was late. Coz that was my routine. And coz of a simple logic, why be excited to wake up early and go to a place you hate and do something that you hate! I sighed when my mouth tasted coffee before colgate...Ahh! how I love normal days, It was a normal day. At least that's what I thought. Papa was there looking up from the newspaper at me with a sense of pity. I sort of ignored that and walked out through the front door, but the next sight, a brand new beautiful ladybird and an even more beautiful rider, with short black hair waving in the wind, in a skirt that knew well not to cover her beautiful legs... Well I couldn't ignore that! Just a fraction of seconds and I had already captured her. Made her mine. Is this what they call... Oops!! She looked at me. Damn it! She caught me staring at her! I looked away whistling. I looked again, did I see a smile? I heard Mom shouting my name out aloud. I knew I had to rush. As I was rushing inside I heard a loud thud. I turned back and saw the beautiful ladybird lying on the road. It was only a fraction of second, yet my mind talked to me in infinite speed...Somethings...what did he say I don't remember anymore. I remember rushing back to the house. One year I didn't talk to our new neighbour who was an year older than me.Days went by. Mom had started packing things up one evening I came back from school. Papa received his transfer letter. Now whenever I see a cycle I think. What would've happened? Why hadn't I stopped my mind talking to me? Why hadn't I I rushed 'out'side than 'in'side? All in a fraction of second! #JOHN PAUL BENOY #Review

Hashtags

Pensive|

@PensivePost · Post #4778 · 20.01.2021 г., 14:26

*FRACTION OF SECONDS* Woke up. I knew I was late. Coz that was my routine. And coz of a simple logic, why be excited to wake up early and go to a place you hate and do something that you hate! I sighed when my mouth tasted coffee before colgate...Ahh! how I love normal days, It was a normal day. At least that's what I thought. Papa was there looking up from the newspaper at me with a sense of pity. I sort of ignored that and walked out through the front door, but the next sight, a brand new beautiful ladybird and an even more beautiful rider, with short black hair waving in the wind, in a skirt that knew well not to cover her beautiful legs... Well I couldn't ignore that! Just a fraction of seconds and I had already captured her. Made her mine. Is this what they call... Oops!! She looked at me. Damn it! She caught me staring at her! I looked away whistling. I looked again, did I see a smile? I heard Mom shouting my name out aloud. I knew I had to rush. As I was rushing inside I heard a loud thud. I turned back and saw the beautiful ladybird lying on the road. It was only a fraction of second, yet my mind talked to me in infinite speed...Somethings...what did he say I don't remember anymore. I remember rushing back to the house. One year I didn't talk to our new neighbour who was an year older than me.Days went by. Mom had started packing things up one evening I came back from school. Papa received his transfer letter. Now whenever I see a cycle I think. What would've happened? Why hadn't I stopped my mind talking to me? Why hadn't I I rushed 'out'side than 'in'side? All in a fraction of second! #JOHN PAUL BENOY #Review #short story

American Оbserver

@american_observer · Post #5212 · 24.02.2026 г., 16:19

Former US National Security Advisor John Bolton: “Although you could potentially remove the ayatollah, that would leave the IRGC in place, and the government in Iran is the IRGC, while the ayatollahs act as a religious cover or an ideological cover for them. I think Trump is just hoping that this show of American power will intimidate the ayatollahs. If I were still his adviser, I would be happy to tell him that it won’t work. They won’t be intimidated. But Trump really thinks minute by minute; he doesn’t think strategically.” #john#bolton#trump#ayatollah 📱American Оbserver - Stay up to date on all important events 🇺🇸