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

Резултати

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

Пребарај: #disruption

当前筛选 #disruption清除筛选
Venture Village Wall 🦄

@venturevillagewall · Post #3856 · 12.01.2025 г., 13:00

Venture Capitalists Seek Unique Startups Harry Stebbings highlights the challenges in securing early investments for billion-dollar startups. He notes that successful startups often face skepticism, as venture funds must invest in uniquely promising ideas that others doubt. This trend raises the question: should you seek agreement or disagreement on your idea? In related news, the music generator JEN-1.5 is now publicly available, focused on licensed content under Warner. However, it lacks quality, providing only basic melodies and no vocal options. While it includes a subscription model for limited generations, it aims to appeal to musicians with its StyleFilter tool, which promises some innovative potential. You can explore JEN-1.5 here. #Startups#Investing#VentureCapital#MusicTech#AI#Innovation#Funding#Entrepreneurship#Disruption#Technology#TechNews

Venture Village Wall 🦄

@venturevillagewall · Post #4029 · 30.01.2025 г., 13:00

From Pet Project to Europe's Top Startup Klarna, founded by three Swedish students in 2005, progressed from an idea into Europe's most valuable startup worth $45.6 billion. Initially losing a school competition, they launched a unique payment service. By offering a secure, easy checkout and features like BNPL, Klarna solved key challenges for sellers and buyers. Despite major fluctuations in valuation, they are now preparing for their IPO. This journey emphasizes resilience in entrepreneurship and the complexities of attracting investments. Read more here. #Klarna#Startup#Europe#FinTech#Payments#BNPL#IPO#Entrepreneurship#Investment#TechInnovation#BusinessGrowth#E-commerce #Sweden#Funding#BusinessModel#TechStartups#FinancialServices#OnlinePayments#Disruption#VentureCapital#AI#Crypto

Venture Village Wall 🦄

@venturevillagewall · Post #3608 · 21.12.2024 г., 07:13

Disrupting Subscription Models A potential billion-dollar startup aims to revolutionize content sales by eliminating subscription models that frustrate users wanting single purchases. Currently, 70% of subscribers cancel within 3-6 months, while content sellers hesitate to switch to one-time payments due to lower profitability. Innovations in this direction could lead to significant market changes. More details here: Fast Founder #Startup#ContentSales#SubscriptionModel#UserExperience#BusinessStrategy#MarketInnovation#OneTimePayment#Profitability#UserRetention#Ecommerce#RevenueModel#Disruption#TechStartup#Media#DigitalContent#OnlineSales#Fintech#Investments#Entrepreneurship#InnovativeIdeas