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

Пребарај: #decipher2024

当前筛选 #decipher2024清除筛选
DWF Labs Broadcast

@DWFLabs · Post #728 · 27.06.2024 г., 08:35

We had a great day yesterday at #Decipher2024 hosted by Algorand Foundation 🔥 Alessia Baumgartner, Business Partner of Ecosystems at DWF Labs, shared about what we look for in our portfolio and tips for pitches. Check out some key insights 👇 1️⃣ Pitch decks should be concise and compelling - communicating the ethos and important aspects of a project within the first two minutes. 2️⃣ Founders with strong technical skills and adaptability are integral to what we look for in projects, as they can adjust their strategies during market fluctuation to ensure success and longevity. 3️⃣ Projects that strongly fulfill key KPIs such as network activity and community engagement have a competitive edge. We're always looking for projects to support - feel free to reach out if you're working on a project, or have a project to share. Let's buidl! 🤝

DWF Labs Broadcast

@DWFLabs · Post #722 · 24.06.2024 г., 02:01

Catch Alessia Baumgartner, Business Partner of Ecosystems at DWF Labs, at #Decipher2024 hosted by Algorand Foundation. She'll be taking the stage at 4.15pm CET on June 26 to discuss what we look for in projects to support and partner with. Don't miss her panel.🔥

DWF Labs Broadcast

@DWFLabs · Post #725 · 26.06.2024 г., 13:57

Could you decipher where we are? 😁 Our Business Partner of Ecosystems, Alessia Baumgartner is taking the stage soon. If you're around and would like to hear more about what we look for in projects, come join us 🔥 #Decipher2024#Algorand#DWFLabs