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

Резултати

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

Пребарај: #glaciers

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

@interesting_planet_facts · Post #517 · 07.08.2025 г., 18:22

🌎 Deep inside Mount Rainier, rare mineral caves called "Paradise Ice Caves" form as flowing air carves tunnels through compacted mountain ice, creating shimmering blue chambers that slowly change shape with the seasons. ✨ #geology⚡#glaciers⚡#minerals 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #591 · 19.08.2025 г., 20:22

🌎 Powerful enough to move mountains, glaciers shaped entire continents. As they advanced, their slow, grinding ice carved out valleys, lakes, and fjords still visible today. ✨ #geology⚡#glaciers⚡#landscapes 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #678 · 03.09.2025 г., 00:22

🌎 Glacial ice cores are frozen natural records of Earth’s past atmosphere. As snow compacts into ice, it traps tiny air bubbles that preserve ancient air. Scientists analyze these bubbles to measure past greenhouse gas levels, revealing climate changes that go back over 800,000 years. ✨ #geology⚡#climatehistory⚡#glaciers 👉subscribe Interesting Planet ​

Interesting Planet 🌍

@interesting_planet_facts · Post #620 · 24.08.2025 г., 13:22

🌎 In the heart of the Torres del Paine National Park in Chile, the Valle del Francés or "French Valley" mystifies visitors with its eerie groaning noises. The sounds come from glaciers cracking and shifting above, sometimes echoing like distant thunder across the silent rocky landscape—a wild reminder of Earth's restless, mysterious forces at work. ✨ #mysteries⚡#glaciers⚡#Chile 👉subscribe Interesting Planet ​

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 #649 · 27.02.2026 г., 20:31

🌍 Rapid melting of glaciers is raising global sea levels faster than expected, contributing to increased flooding risks in coastal cities and threatening freshwater supplies for millions worldwide. ✨ #climate⚡#glaciers⚡#flooding⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #228 · 13.09.2025 г., 09:12

🌍 Some mountain glaciers now lose over a meter of thickness each year due to warming temperatures. This rapid melt threatens fresh water supplies for millions living downstream. ✨ #glaciers⚡#climate⚡#water⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #699 · 23.04.2026 г., 20:31

🌍 Antarctica is home to “blue ice” areas where strong winds strip away snow and expose centuries-old glacier ice, creating shimmering fields that reflect nearly as much sunlight as fresh snow. ✨ #glaciers⚡#Antarctica⚡#polar⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #658 · 11.03.2026 г., 20:31

🌍 In Antarctica’s Dry Valleys, glaciers flow slowly over bare rock and create icy waterfalls called “ice falls,” frozen in mid-cascade for years in the planet’s coldest, driest desert region. ✨ #glaciers⚡#Antarctica⚡#polar⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #237 · 14.09.2025 г., 20:12

🌍 In Antarctica’s McMurdo Dry Valleys, some glaciers create striking red waterfalls called “Blood Falls.” The color comes from iron-rich water oxidizing as it flows out of the ice. ✨ #glaciers⚡#polar⚡#Antarctica⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #163 · 02.09.2025 г., 16:12

🌍 Some Antarctic glaciers can move several meters in a single day, driven by gravity and melting underneath. These "ice rivers" shape the landscape faster than most people imagine. ✨ #glaciers⚡#polar⚡#Antarctica⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

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