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

Резултати

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

Пребарај: #africatech

当前筛选 #africatech清除筛选

🚀ETHIOPIA GOES DIGITAL: ADDIS ABABA LAUNCHES SCOOTER SHARING! ኢትዮጵያ ወደ ዲጂታል ይሄዳል፡ አዲስ አበባ የስኪቴር ማጋራት ጀምራለች! 💫ADDIS BIKE - THE FUTURE IS HERE: • First electric scooter sharing in Horn of Africa! 🌍 • Digital registration through Ethiopian national ID • Bole Avenue route: Meskel Square → Airport 🛩️ • Speed limit: 20 km/h for safety • Cost: 5 birr/minute, 300 birr/hour ($2 USD) 🎯YOUTH REVOLUTION: Ethiopian millennials are embracing smart mobility! From ancient coffee ceremonies to modern app-based transport - this is how traditions meet innovation! 🚴‍♀️INFRASTRUCTURE READY: Dedicated bike lanes, proper equipment, safety first approach - Addis Ababa is building smart city infrastructure! 💻ETHIOPIA'S TECH BOOM: • IceAddis - leading tech hub and startup incubator • Growing fintech sector with mobile banking solutions • Government digitalization initiatives • Young developers creating apps for African market • 5G network rollout in major cities 🌐DIGITAL TRANSFORMATION: From traditional markets to digital payments - Ethiopia is building Africa's Silicon Valley in the heart of the continent! ✨SYMBOLIC MOMENT: From Lucy's first steps 3.2 million years ago to electric scooters today - Ethiopia continues to lead human mobility evolution in Africa! 🇪🇹 #EthiopiaDigital#AddisAbaba#SmartMobility#AfricaTech#ኢትዮጵያ🛴⚡📱

💻 FROM ANCIENT SCRIPTS TO DIGITAL CODE: ETHIOPIA'S TECH TAKEOVER 💻 ከጥንታዊ ጽሑፍ እስከ ዲጂታል ኮድ: የኢትዮጵያ ቴክኖሎጂ መቆጣጠር 🔥 КОГДА 3000-ЛЕТНЯЯ ЦИВИЛИЗАЦИЯ ВСТРЕЧАЕТ SILICON VALLEY! Ethiopian youth aren't just consuming technology - they're CREATING it! 💫 🌟 DIGITAL ETHIOPIA RISING: 🏙️ ADDIS ABABA = AFRICA'S SILICON VALLEY: - Tech hubs sprouting faster than coffee plants - Young developers coding the future of Africa - From ancient Ge'ez script to programming languages! 💡 ETHIOPIAN TECH STARTUPS CHANGING THE GAME: 🚀Ride - Ethiopia's answer to Uber, built for African roads 🚀ZayRide - Local mobility solutions that actually work 🚀Deliver Addis - Food delivery revolutionizing Ethiopian dining 🚀EthSwitch - Fintech making banking accessible to everyone 🚀Gebeya - Training Africa's next generation of developers 🚀iCog Labs - AI and robotics putting Ethiopia on the tech map 📊 THE NUMBERS DON'T LIE: ✨ 50%+ youth population = MASSIVE tech potential ✨ Growing internet penetration = Digital revolution in motion ✨ Government support for tech initiatives = Infrastructure backing innovation ✨ Ancient problem-solving culture + Modern tools = Unstoppable combination 🎯 YOUNG ETHIOPIAN DEVELOPERS SAY: *"Our ancestors built Lalibela without blueprints - we build apps without limits!"* *"ቅድመ አያቶቻችን ላሊበላን ያለ ንድፍ ገንብተዋል - እኛ ያለ ገደብ መተግበሪያዎችን እንገነባለን!"* 🔋 THE DIGITAL SWAG: - Coding in multiple languages (including Amharic interfaces!) - Building solutions for African problems - Connecting rural Ethiopia to global markets - Making ancient wisdom accessible through modern tech 🚀 PLOT TWIST: While Silicon Valley talks about "disruption," Ethiopia has been disrupting expectations for millennia! 💪 THE FUTURE IS BEING WRITTEN: In Ethiopian coffee shops, young developers are coding solutions that will change Africa forever! *From coffee ceremonies to coding ceremonies - the grind never stops* ☕💻 #DigitalEthiopia#የኢትዮጵያቴክኖሎጂ#EthiopianTech#AfricaTech#TechStartups#DigitalRevolution#EthiopianInnovation#TechHub#ኢትዮጵያላይፍ#FutureIsEthiopian