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

Резултати

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

Пребарај: #novels

当前筛选 #novels清除筛选
Velvet Pages | eLibrary 🥂

@bookslibraryofficial · Post #1397 · 15.08.2025 г., 14:48

📖Title : The Return of the King ✍️Author : J.R.R. Tolkien ⭐️Rating : 4.58/5 (Goodreads) 📆Published : Oct 20, 1955 ———————————————— Summary:In The Return of the King, the final volume of J.R.R. Tolkien’s The Lord of the Rings, the forces of Gondor and Rohan prepare for the ultimate battle against Sauron. Aragorn embraces his destiny as the true king, rallying allies and marching to the Black Gate as a diversion. Meanwhile, Frodo and Sam struggle through Mordor to destroy the One Ring in Mount Doom. Gollum’s obsession leads to his and the Ring’s destruction, ending Sauron’s reign. Peace returns to Middle-earth, Aragorn is crowned, and the hobbits return to a changed Shire. Frodo later departs with the Elves to the Undying Lands. ———————————————— #fantasy#fiction#classics#adventure#novels#LOTR@Bookslibraryofficial@free_novellas@thesciencelabs

Velvet Pages | eLibrary 🥂

@bookslibraryofficial · Post #1391 · 04.08.2025 г., 15:29

📖Title : The Two Towers ✍️Author : J.R.R. Tolkien ⭐️Rating : 4.50/5 (Goodreads) 📆Published : Nov 11, 1954 ———————————————— Summary:In The Two Towers, the Fellowship is broken. Frodo and Sam continue their perilous journey to Mordor to destroy the One Ring, joined reluctantly by the treacherous yet pitiful Gollum, who becomes both guide and threat. Meanwhile, Aragorn, Legolas, and Gimli pursue the Uruk-hai who have captured Merry and Pippin. Their paths lead to the war-torn kingdom of Rohan, where they aid King Théoden against the forces of Saruman. As darkness spreads and war looms, alliances are tested and hope flickers. The story deepens the moral complexity of the quest, showing how power corrupts and loyalty defines true heroism. ———————————————— #fantasy#fiction#classics#adventure#novels#LOTR@Bookslibraryofficial@free_novellas@thesciencelabs

Telegram 公眾索引頻道

@TG_index_channel · Post #1484 · 27.04.2021 г., 01:40

標題:兽人小说|獸人小説 類別:#公開#頻道#簡中 分類:#閒聊#資源#社群#中文圈#NSFW 標籤:#novels#reading#獸人#furry#小説#閲讀 簡介:獸人小説 @FurryNovels 獸獸分享的獸人小説頻道 加群即可參與分享! #furry#novels#reading#NSFW #獸人#閲讀#小説 TG指南 te.legra.ph/TNTwwxs-09-08-06 中文群組 https://t.me/FurryNovels/27