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

Резултати

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

Пребарај: #hydrology

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

@amazingeo · Post #193 · 07.09.2025 г., 13:12

🌍 The world’s shortest river, the Roe River in Montana, flows only about 61 meters from its source to its mouth. Despite its tiny length, it’s officially recognized as a river. ✨ #rivers⚡#hydrology⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #669 · 22.03.2026 г., 20:31

🌍 Water molecules in the ocean today could have once traveled through glaciers, rivers, or clouds—completing a global journey called the water cycle that never truly ends. ✨ #hydrology⚡#watercycle⚡#earth⚡#geography⚡#nature 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #134 · 28.08.2025 г., 20:12

🌍 Some of the water we drink today has cycled through dinosaurs and ancient forests. Water molecules can take thousands of years to complete a single journey through the global water cycle. ✨ #hydrology⚡#watercycle⚡#earth⚡#geography⚡#nature 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #589 · 23.01.2026 г., 20:31

🌍 The Amazon River’s water travels over 6,400 kilometers from Andes glaciers to the Atlantic, but some of its rain comes from clouds recycled multiple times through plant evaporation along the journey. ✨ #hydrology⚡#rivers⚡#rainforest⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #287 · 23.09.2025 г., 15:31

🌍 Rivers in the Amazon basin recycle rainwater so efficiently that a single water droplet may fall as rain and evaporate back into the sky up to seven times before leaving the forest. ✨ #hydrology⚡#rainforest⚡#rivers⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #627 · 12.02.2026 г., 12:31

🌍 Water in the atmosphere is always on the move—at any moment, only about 0.001% of Earth’s water is in the air as vapor, yet this tiny fraction drives all rain, snow, and weather worldwide. ✨ #hydrology⚡#watercycle⚡#atmosphere⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #327 · 03.10.2025 г., 15:31

🌍 Water vapor in the air isn’t just invisible—it’s crucial for moving energy around the planet. When vapor condenses into clouds, it releases heat that drives weather systems worldwide. ✨ #hydrology⚡#atmosphere⚡#watercycle⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #367 · 13.10.2025 г., 15:31

🌍 Water trapped as snow and ice in the Himalayas slowly melts each spring, feeding rivers that bring life to billions across Asia. This seasonal meltwater is key to the region’s water cycle. ✨ #hydrology⚡#rivers⚡#glaciers⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #316 · 30.09.2025 г., 18:31

🌍 Some of the world’s longest underground rivers are hidden in karst landscapes. These rivers can travel for dozens of kilometers beneath the surface before emerging in springs or caves. ✨ #caves⚡#karst⚡#hydrology⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #440 · 07.11.2025 г., 20:31

🌍 Atmospheric rivers—narrow bands of moisture in the sky—can carry more water than the Amazon River. When these “rivers in the air” hit land, they unleash heavy rains and reshape water cycles. ✨ #hydrology⚡#rainfall⚡#climate⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #246 · 16.09.2025 г., 09:12

🌍 About 90% of the water exchanged in the global water cycle happens over the oceans, not land. Yet this invisible ocean-to-sky movement powers most of the world’s rainfall. ✨ #hydrology⚡#watercycle⚡#oceans⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #488 · 01.12.2025 г., 20:31

🌍 Recent satellites can map changes in Earth's gravity from space. This helps track shifting water underground after floods or droughts, revealing hidden changes on a continental scale. ✨ #remote-sensing ⚡#satellites⚡#hydrology⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

12
ПретходнаСтраница 1 од 2Следна