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

Резултати

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

Пребарај: #distance

当前筛选 #distance清除筛选
Amazing Geography 🌍

@amazingeo · Post #42 · 13.08.2025 г., 16:12

🌍 The world's longest straight-line journey between two points using only latitude and longitude runs over 13,589 km from Liberia on Africa’s coast to eastern China, crossing no ocean. ✨ #coordinates⚡#distance⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Universe Mysteries 🪐

@cosmomyst · Post #510 · 20.11.2025 г., 22:21

🪐 The galaxy JADES-GS-z14-0, discovered in 2023 with the James Webb Space Telescope, is one of the farthest objects ever seen—its light has traveled for about 13.5 billion years to reach Earth. Observing JADES-GS-z14-0 lets astronomers look back to when the universe was less than 300 million years old, offering a rare glimpse into the early stages of galaxy formation just after the Big Bang. ✨ #galaxies⚡#distance⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #474 · 02.11.2025 г., 22:21

🪐 The James Webb Space Telescope has spotted galaxy JD1 (also known as MACS0647-JD1), whose light began its journey over 13.3 billion years ago—when the universe was only about 4% of its current age. Observing JD1 allows scientists to study what galaxies looked like close to the cosmic dawn, revealing the structure of the universe in its earliest moments. ✨ #galaxies⚡#distance⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #446 · 19.10.2025 г., 12:21

🪐 The galaxy CEERS-93316, discovered by the James Webb Space Telescope, is one of the most distant galaxies ever observed—its light began traveling toward us more than 13.4 billion years ago. Seeing CEERS-93316 means we are looking back in time to when the universe was less than 300 million years old, just a tiny fraction of its current age, revealing the earliest stages of galaxy formation after the Big Bang. ✨ #galaxies⚡#distance⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #409 · 11.10.2025 г., 20:21

🪐 The galaxy named Earendel’s host, WHL0137-LS, contains the most distant single star ever detected—a star nicknamed Earendel whose light has taken about 12.9 billion years to reach Earth. Thanks to a powerful gravitational lens (a natural "magnifying glass" formed by another galaxy cluster), the Hubble Space Telescope was able to spot Earendel, offering a rare view of a lone star shining when the universe was less than a billion years old. ✨ #universe⚡#distance⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #378 · 05.10.2025 г., 18:21

🪐 The galaxy ZF-COSMOS-20115, located more than 12 billion light-years from Earth, surprised astronomers by being "dead"—no longer forming new stars—when the universe was just 1.7 billion years old. Studying such distant, quenched galaxies helps scientists understand how some of the earliest cosmic structures formed and evolved in the young universe, illuminating the extreme environments at the farthest reaches of space and time. ✨ #galaxies⚡#distance⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #278 · 16.09.2025 г., 00:11

🪐 The galaxy Maisie’s Galaxy (CEERS-93316), discovered by the James Webb Space Telescope, is one of the most distant objects ever observed, with its light traveling for about 13.4 billion years to reach Earth. We're seeing Maisie’s Galaxy as it existed just a few hundred million years after the Big Bang, providing a rare glimpse into the universe's earliest moments when the first galaxies were assembling and stars began to shine. ✨ #universe⚡#distance⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Amazing Geography 🌍

@amazingeo · Post #408 · 23.10.2025 г., 18:31

🌍 The world’s longest scheduled nonstop passenger flight connects New York and Singapore, covering about 15,300 kilometers in nearly 19 hours—highlighting advances in global air transport geography. ✨ #aviation⚡#distance⚡#networks⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Universe Mysteries 🪐

@cosmomyst · Post #230 · 06.09.2025 г., 03:11

🪐 The galaxy HD1, discovered in 2022, may be the most distant known object in the universe—its light has traveled more than 13.5 billion years to reach us. Observing HD1 gives astronomers a rare window into the universe just 300 million years after the Big Bang, offering clues to how the earliest galaxies and stars began to form in the cosmic dawn. ✨ #galaxies⚡#distance⚡#earlyuniverse⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries ​

Universe Mysteries 🪐

@cosmomyst · Post #560 · 15.12.2025 г., 22:21

🪐 The James Webb Space Telescope has observed the galaxy JADES-GS-z7-01-QU, one of the most distant “quiescent” galaxies ever found, meaning it has stopped making new stars even though its light began traveling to us over 13 billion years ago. Seeing JADES-GS-z7-01-QU lets scientists study how some galaxies aged and shut down astonishingly early, offering a rare glimpse into the universe’s remote past when cosmic structures were just beginning to take shape. ✨ #galaxies⚡#distance⚡#telescopes⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​