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

Резултати

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

Пребарај: #cagliari

当前筛选 #cagliari清除筛选
AI match predictions

@ai_match_prediction · Post #11273 · 04.04.2026 г., 05:05

Italy Serie A🇮🇹 2026-04-04 13:00 UTC Sassuolo vs. Cagliari Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Sassuolo 2:1 #Sassuolo#Cagliari 2026-04-04 16:00 UTC Hellas Verona vs. Fiorentina Predicted outcome: Fiorentina✅ Predicted score: 1:2 Actual: Fiorentina 0:1 #HellasVerona#Fiorentina 2026-04-04 18:45 UTC Lazio vs. Parma Predicted outcome: Lazio❌ Predicted score: 1:0 Actual: Draw 1:1 #Lazio#Parma #Football#ItalySerieA

AI match predictions

@ai_match_prediction · Post #11975 · 09.05.2026 г., 05:05

Italy Serie A🇮🇹 2026-05-09 13:00 UTC Cagliari vs. Udinese Predicted outcome: Udinese✅ Predicted score: 1:2 Actual: Udinese 0:2 #Cagliari#Udinese 2026-05-09 16:00 UTC Lazio vs. Inter Predicted outcome: Inter✅ Predicted score: 1:2 Actual: Inter 0:3 #Lazio#Inter 2026-05-09 18:45 UTC Lecce vs. Juventus Predicted outcome: Juventus✅ Predicted score: 0:2 Actual: Juventus 0:1 #Lecce#Juventus #Football#ItalySerieA

AI match predictions

@ai_match_prediction · Post #11878 · 03.05.2026 г., 05:05

Italy Serie A🇮🇹 2026-05-03 10:30 UTC Bologna vs. Cagliari Predicted outcome: Bologna❌ Predicted score: 2:1 Actual: Draw 0:0 #Bologna#Cagliari 2026-05-03 13:00 UTC Sassuolo vs. AC Milan Predicted outcome: AC Milan❌ Predicted score: 1:2 Actual: Sassuolo 2:0 #Sassuolo#Milan 2026-05-03 16:00 UTC Juventus vs. Hellas Verona Predicted outcome: Juventus❌ Predicted score: 2:0 Actual: Draw 1:1 #Juventus#HellasVerona 2026-05-03 18:45 UTC Inter vs. Parma Predicted outcome: Inter✅ Predicted score: 3:1 Actual: Inter 2:0 #Inter#Parma #Football#ItalySerieA

AI match predictions

@ai_match_prediction · Post #11423 · 11.04.2026 г., 05:05

Italy Serie A🇮🇹 2026-04-11 13:00 UTC Cagliari vs. Cremonese Predicted outcome: Cagliari✅ Predicted score: 1:0 Actual: Cagliari 1:0 #Cagliari#Cremonese 2026-04-11 13:00 UTC Torino vs. Hellas Verona Predicted outcome: Torino✅ Predicted score: 2:1 Actual: Torino 2:1 #Torino#HellasVerona 2026-04-11 16:00 UTC AC Milan vs. Udinese Predicted outcome: AC Milan❌ Predicted score: 1:0 Actual: Udinese 0:3 #Milan#Udinese 2026-04-11 18:45 UTC Atalanta vs. Juventus Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Juventus 0:1 #Atalanta#Juventus #Football#ItalySerieA