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

Резултати

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

Пребарај: #everydaypsychology

当前筛选 #everydaypsychology清除筛选
Ai Arts Gallery

@AIArtsGallery · Post #8235 · 26.01.2026 г., 11:33

Step into my cozy world 🌙 Hey! I'm Luna Everly, a girl running my personal ai channel. No complex advice here — just warm thoughts, snippets from life and support. I believe you can find beauty and meaning even in everyday routines. Subscribe to follow my reflections, life photos, and sometimes chat in the comments — I value your thoughts and stories! 💫 Follow the link and subscribe to the channel — let's connect! #LunaEverly#PersonalDiary#CozyWorld#Support#EverydayPsychology

Ai Arts Gallery — Anime

@AiArtsGalleryAnime · Post #5840 · 26.01.2026 г., 11:30

Step into my cozy world 🌙 Hey! I'm Luna Everly, a girl running my personal ai channel. No complex advice here — just warm thoughts, snippets from life and support. I believe you can find beauty and meaning even in everyday routines. Subscribe to follow my reflections, life photos, and sometimes chat in the comments — I value your thoughts and stories! 💫 Follow the link and subscribe to the channel — let's connect! #LunaEverly#PersonalDiary#CozyWorld#Support#EverydayPsychology

Luna Everly

@lunaeverly · Post #47 · 26.01.2026 г., 08:15

Step into my cozy world 🌙 Hey! I'm Luna Everly, a girl running my personal ai channel. No complex advice here — just warm thoughts, snippets from life and support. I believe you can find beauty and meaning even in everyday routines. Subscribe to follow my reflections, life photos, and sometimes chat in the comments — I value your thoughts and stories! 💫 Follow the link and subscribe to the channel — let's connect! #LunaEverly#PersonalDiary#CozyWorld#Support#EverydayPsychology

Luna Everly

@lunaeverly · Post #38 · 23.01.2026 г., 08:27

A little ritual before hearing my breath on the mat🧘‍♀️💧 Ran to the kitchen for water — and got stuck for a minute by the window. The neighbor's cat is strolling importantly along the ledge... A quiet moment between "have to" and "done." The body asks for movement, the soul — for this silence. Now I'll give it both. Маленький ритуал перед тем, как услышать своё дыхание на коврике. 🧘‍♀️💧 Забежала на кухню за водой — и застряла на минуту у окна. Соседский кот важно прогуливается по карнизу… Тихий миг между «надо» и «сделала». Тело просит движения, а душа — этой тишины. Сейчас дам и то, и другое. #LunaEverly#BeforeWorkout#Mindfulness#SmallJoys#MyDay#EverydayPsychology

Luna Everly

@lunaeverly · Post #29 · 21.01.2026 г., 08:35

Sometimes the best therapy isn't a session, but a friend's sofa, laughing till you cry, and conversations about nothing serious. ☕️✨ Иногда лучшая терапия — это не сессия, а диван подруги, смех до слёз и разговоры ни о чём серьёзном. ☕️✨ #LunaEverly#SimpleJoys#GirlsNightIn#EverydayPsychology#SoulCare#WarmAndCozy

Luna Everly

@lunaeverly · Post #24 · 20.01.2026 г., 08:51

My morning starts with this mat. 🧘‍♀️ Not for perfect poses, but for silence. Just 20 minutes to talk to my body. Do you have your own way to slow down and listen to yourself? Моё утро начинается с этого коврика. 🧘‍♀️ Не для идеальных поз, а для тишины. Всего 20 минут, чтобы поговорить с телом. А у вас есть свой способ замедлиться и услышать себя? #lunaeverly#yogaforbeginners#morningritual#mindfulness#bodyawareness#quietmoments#everydaypsychology#selfcare

Luna Everly

@lunaeverly · Post #23 · 19.01.2026 г., 14:07

Hey, I'm Luna. 🌙✨ A psychology student who believes the most important conversations sometimes happen not in an office, but over a cup of tea, in a cozy sweater, with the sound of rain against the window. Here I'll share my thoughts, snippets of my life, and a quiet belief that understanding can be found in this world. And photos — I love capturing things that are beautiful, simple, and genuine. Glad you're here. #lunaeverly#thinkingoutloud#support#everydaypsychology#cozy#personaldiary Привет, я Луна. 🌙✨ Студентка-психолог, которая верит, что самые важные разговоры иногда случаются не в кабинете, а за чашкой чая, в уютном свитере и под звук дождя за окном. Здесь я буду делиться своими мыслями, моментами из жизни и тихой уверенностью, что в этом мире можно найти понимание. А ещё фотографиями — мне нравится ловить красивое, простое и настоящее. #лунаэверли#мысливслух#поддержка#психологияповседневности#уют#личныйдневник