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

Резултати

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

Пребарај: #microbiology

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

@interesting_planet_facts · Post #423 · 26.07.2025 г., 03:22

🌎 In the world’s caves, “moonmilk” forms as a creamy white mineral paste, oozing from rock walls. Created by bacteria that slowly dissolve limestone, moonmilk has been used for centuries as folk medicine by local cultures. ✨ #geology⚡#microbiology⚡#caves 👉subscribe Interesting Planet

Amazing Geography 🌍

@amazingeo · Post #469 · 22.11.2025 г., 12:31

🌍 Some karst caves contain rare bacteria that feed on mineral rock, creating colorful biofilms and even helping form new cave crystals—making the underground world alive in ways few people expect. ✨ #caves⚡#karst⚡#microbiology⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #578 · 15.01.2026 г., 20:31

🌍 Some polar lakes never see sunlight and stay covered with ice year-round. Microbes living under this ice survive in complete darkness, making them some of the most isolated life forms on Earth. ✨ #glaciers⚡#polar⚡#microbiology⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #466 · 30.07.2025 г., 13:22

🌎 In the dry canyons of the American Southwest, cryptobiotic soil forms a living crust of bacteria, fungi, and lichens. This fragile layer stabilizes desert soil and helps seeds germinate, supporting entire ecosystems in these harsh climates. ✨ #desert⚡#microbiology⚡#ecosystems 👉subscribe Interesting Planet

Venture Village Wall 🦄

@venturevillagewall · Post #4210 · 21.02.2025 г., 16:00

Latest Funding Rounds in Tech & Agri Funding highlights: - Johnvents Industries: $40.5M - Indigenous agribusiness in Africa. Read more - Valencia Technologies: $35M - Focused on tech innovations. Read more - Certn: $30M - Efficient background screening solutions. Read more - EG 427: $28.17M - DNA medicines for chronic diseases. Read more - Methuselah: $27.46M - Medical technology advancements. Read more - Spore.bio: $23M - Innovations in microbiology. Read more - Avandra Imaging: $17.75M - Imaging technology developments. Read more - Nuveen Green Capital: $15M - Sustainable real estate financing. Read more - METYCLE: $14.71M - Supplier access and product sales. Read more - fileAI: $14M - AI file automation solutions. Read more #Funding#Agribusiness#Tech#Sustainable#BackgroundCheck#Healthcare#MedicalTech#Microbiology#RealEstate#AI