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

Пребарај: #companies

当前筛选 #companies清除筛选
Bali News

@balinews · Post #261 · 12.12.2024 г., 13:45

🏭Manufacturer of Smirnoff, Captain Morgan and Guiness expands production in Bali 📰 One of the world's largest producers of alcoholic beverages, the British company Diageo, is expanding its production in Bali. 8,800 m² of production capacity will be added to the existing factory in the Tabanan area. 🗺 Diageo is the owner of such global brands as Captain Morgan rum, Johnnie Walker whisky, Smirnoff vodka and Guinness beer. The company is betting on increasing sales not only in Indonesia but in the entire Southeast Asian region. ↗️ The factory has been operating in Bali since 2014, and products have been exported to other Southeast Asian countries since 2021. According to Diageo representatives, this region accounts for 19% of total sales. 🎯 The company has big plans for the renovated plant. Bali's strategic location makes it a convenient center for a production hub not only for Southeast Asia, but also for the entire Asia-Pacific region. @BaliNews #companies#business

Venture Village Wall 🦄

@venturevillagewall · Post #4320 · 06.03.2025 г., 10:00

Tether Freezes Garantex USDT Accounts ⚠️ Tether has frozen Garantex's USDT accounts worth over 2.5 billion rubles, forcing the exchange to suspend all services, including crypto withdrawals. Read more: hashtelegraph.com 💵 In other news, OpenAI plans to charge up to $20,000 per month for specialized AI agents aimed at various sectors. Details: forklog.com 💰 The global venture capital funding dropped to $19 billion in February, with AI startups receiving 30% of investments. Source: Crunchbase #Tether#Garantex#USDT#AI#Crypto#VC#Solana#Cardano#Canoo#companies#startups#funding#blockchain#fintech#venturecapital#innovation#technology#analytics#automotive#delivery#robotics