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 слични објави

Пребарај: #capitalization

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

@venturevillagewall · Post #3439 · 19.12.2024 г., 08:00

Exodus Surges on NYSE Debut Exodus, a developer of non-custodial software, debuted on the NYSE under the ticker EXOD, achieving an impressive 36% growth during its first trading session. The company's market capitalization reached $1.4 billion. #Exodus#NYSE#software#growth#debut#trading#capitalization#market#stocks#investments

Venture Village Wall 🦄

@venturevillagewall · Post #3592 · 20.12.2024 г., 13:00

First Combined Bitcoin-Ethereum ETFs Approved ✅ The SEC has approved the first combined spot ETFs for Bitcoin and Ethereum from Hashdex and Franklin Templeton. Asset allocation will be based on market capitalization, with Bloomberg analysts projecting a weight of approximately 80% Bitcoin and 20% Ethereum, reflecting current asset evaluations. Read more #SEC#ETF#Bitcoin#Ethereum#Hashdex#FranklinTempleton#Bloomberg#Crypto#Finance#Investment#Market#Assets#Approval#SpotETFs#Capitalization#Trading#AssetsAllocation#Investing#DigitalAssets#InvestmentStrategy

Venture Village Wall 🦄

@venturevillagewall · Post #3442 · 19.12.2024 г., 10:59

Investors Eye Russian M&A Boom Investment activity in Russia is on the rise, with a surge in mergers and acquisitions along with simplified IPO processes. Founders are encouraged to connect with key strategists and investors to navigate these opportunities effectively. Notably, investor Alexander Radionov, owner of M&A boutique and foodtech companies Broniboy and Bumеrang, shares insights on capital growth and successful exits on his channel. He monitors promising projects and organizes events for founders to facilitate company sales ripe for exit. Explore his channel for valuable resources on capitalization growth and exit strategies. #Investment#M&A #IPO#Russia#BusinessGrowth#ExitStrategies#FoodTech#AlexanderRadionov#Broniboy#Bumeеrang#Capitalization#InvestorConnections#Mergers#Acquisitions#PrivateEquity#Entrepreneurship#Growth#Success#BusinessSales#MarketTrends