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

Резултати

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

Пребарај: #bioluminescence

当前筛选 #bioluminescence清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #1240 · 20.01.2026 г., 18:11

🌎 Glowing deep-sea animals like the comb jellyfish and dragonfish create their own light using bioluminescence. This adaptation helps them hunt, attract mates, or avoid predators in pitch-black ocean depths. Some dragonfish possess "invisible" red bioluminescence, seen only by their own kind, for stealthy communication. ✨ #ocean⚡#animals⚡#bioluminescence 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #392 · 19.10.2025 г., 18:31

🌍 The Waitomo Glowworm Caves in New Zealand are famous for thousands of tiny insects that light up the darkness, creating a galaxy-like effect in this unique karst underground world. ✨ #caves⚡#karst⚡#bioluminescence⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #661 · 31.08.2025 г., 03:22

🌎 Shrouded in darkness, the “midnight zone” of the ocean lies below 1,000 meters, where sunlight can’t reach and pressure crushes like a dozen elephants. Creatures here glow with bioluminescence and withstand freezing cold, revealing how life adapts to our planet’s most mysterious depths. ✨ #ocean⚡#bioluminescence⚡#deepsea 👉subscribe Interesting Planet ​

Interesting Planet 🌍

@interesting_planet_facts · Post #471 · 31.07.2025 г., 00:22

🌎 Lightning bugs, or fireflies, create their glow through a special enzyme called luciferase. This reaction produces cold light, wasting almost no energy as heat—a marvel of natural engineering for nighttime signaling. ✨ #bioluminescence⚡#insects⚡#nature 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1056 · 20.11.2025 г., 18:11

🌎 Glowing tides known as bioluminescent bays light up in places like Puerto Rico. Microorganisms called dinoflagellates produce blue-green light when stirred by waves or movement. The brightest, Mosquito Bay, can host up to 700,000 glowing organisms in just one liter of water. ✨ #bioluminescence⚡#ocean⚡#phenomenon 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #659 · 12.03.2026 г., 20:31

🌍 Some coasts shine with glowing “blue waves” at night, caused by tiny plankton called dinoflagellates emitting light when disturbed—a dazzling phenomenon known as marine bioluminescence. ✨ #seas⚡#coastline⚡#bioluminescence⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1379 · 20.04.2026 г., 12:11

🌎 Glowing waves known as “sea sparkle” can light up coastlines at night. This effect is caused by bioluminescent plankton emitting blue light when disturbed. Some blooms stretch for kilometers and are most often seen in warm coastal waters. ✨ #bioluminescence⚡#ocean⚡#plankton 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #396 · 23.07.2025 г., 16:22

🌎 Glowing waves sometimes light up the ocean at night thanks to bioluminescent plankton. These tiny marine organisms emit blue light when disturbed, turning shorelines into breathtaking, natural light shows. ✨ #ocean⚡#bioluminescence⚡#plankton 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #384 · 22.07.2025 г., 13:22

🌎 The vampire squid thrives in the ocean’s dark depths by using bioluminescent light organs to confuse predators. Its name comes from its cloak-like webbed arms, not from blood-drinking. ✨ #ocean⚡#cephalopod⚡#bioluminescence 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #597 · 20.08.2025 г., 20:22

🌎 In the Mediterranean Sea, the bearded fireworm boasts bristly, glowing spines that can cause a painful sting. This marine worm’s bioluminescence warns predators while its venomous bristles deter unwelcome touches—a perfect example of nature’s flashy, double-edged defense system. ✨ #fireworm⚡#bioluminescence⚡#ocean 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #696 · 06.09.2025 г., 00:22

🌎 Somewhere in the world’s oceans, the “milky sea” phenomenon can make water glow bright blue for up to several days. Caused by massive colonies of bioluminescent bacteria, these rare glowing patches can cover areas larger than 15,000 square kilometers—visible even from space. ✨ #ocean⚡#mysteries⚡#bioluminescence⚡#bacteria 👉subscribe Interesting Planet ​