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

Пребарај: #falkirk

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

@ai_match_prediction · Post #12082 · 13.05.2026 г., 13:05

Scotland Premiership🏴󠁧󠁢󠁳󠁣󠁴󠁿 2026-05-13 19:00 UTC Heart Of Midlothian vs. Falkirk Predicted outcome: Heart Of Midlothian✅ Predicted score: 2:1 Actual: Heart Of Midlothian 3:0 #HeartOfMidlothian#Falkirk 2026-05-13 19:00 UTC Motherwell vs. Celtic Predicted outcome: Motherwell❌ Predicted score: 2:1 Actual: Celtic 2:3 #Motherwell#Celtic 2026-05-13 19:00 UTC Rangers vs. Hibernian Predicted outcome: Rangers❌ Predicted score: 2:1 Actual: Hibernian 1:2 #Rangers#Hibernian #Football#ScotlandPremiership

AI match predictions

@ai_match_prediction · Post #11859 · 02.05.2026 г., 09:06

Scotland Premiership🏴󠁧󠁢󠁳󠁣󠁴󠁿 2026-05-02 14:00 UTC Kilmarnock vs. Dundee Utd Predicted outcome: Dundee Utd❌ Predicted score: 2:3 Actual: Kilmarnock 3:0 #Kilmarnock#DundeeUtd 2026-05-02 14:00 UTC Dundee vs. ST Mirren Predicted outcome: Dundee✅ Predicted score: 2:1 Actual: Dundee 1:0 #Dundee#STMirren 2026-05-02 14:00 UTC Falkirk vs. Motherwell Predicted outcome: Motherwell❌ Predicted score: 1:2 Actual: Falkirk 1:0 #Falkirk#Motherwell #Football#ScotlandPremiership

AI match predictions

@ai_match_prediction · Post #11732 · 25.04.2026 г., 09:06

Scotland Premiership🏴󠁧󠁢󠁳󠁣󠁴󠁿 2026-04-25 14:00 UTC ST Mirren vs. Livingston Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Livingston 0:2 #STMirren#Livingston 2026-04-25 14:00 UTC Aberdeen vs. Kilmarnock Predicted outcome: Aberdeen✅ Predicted score: 2:1 Actual: Aberdeen 1:0 #Aberdeen#Kilmarnock 2026-04-25 16:30 UTC Celtic vs. Falkirk Predicted outcome: Celtic✅ Predicted score: 2:1 Actual: Celtic 3:1 #Celtic#Falkirk #Football#ScotlandPremiership

AI match predictions

@ai_match_prediction · Post #11290 · 04.04.2026 г., 09:07

Scotland Premiership🏴󠁧󠁢󠁳󠁣󠁴󠁿 2026-04-04 14:00 UTC Hibernian vs. Kilmarnock Predicted outcome: Hibernian✅ Predicted score: 2:1 Actual: Hibernian 3:0 #Hibernian#Kilmarnock 2026-04-04 14:00 UTC ST Mirren vs. Aberdeen Predicted outcome: Draw❌ Predicted score: 1:1 Actual: ST Mirren 2:0 #STMirren#Aberdeen 2026-04-04 14:00 UTC Motherwell vs. Falkirk Predicted outcome: Motherwell❌ Predicted score: 1:0 Actual: Falkirk 2:3 #Motherwell#Falkirk 2026-04-04 14:00 UTC Rangers vs. Dundee Utd Predicted outcome: Rangers✅ Predicted score: 3:1 Actual: Rangers 4:2 #Rangers#DundeeUtd #Football#ScotlandPremiership

AI match predictions

@ai_match_prediction · Post #11988 · 09.05.2026 г., 09:06

Scotland Premiership🏴󠁧󠁢󠁳󠁣󠁴󠁿 2026-05-09 14:00 UTC ST Mirren vs. Kilmarnock Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Kilmarnock 0:3 #STMirren#Kilmarnock 2026-05-09 14:00 UTC Aberdeen vs. Dundee Utd Predicted outcome: Aberdeen✅ Predicted score: 2:1 Actual: Aberdeen 2:0 #Aberdeen#DundeeUtd 2026-05-09 14:00 UTC Dundee vs. Livingston Predicted outcome: Dundee✅ Predicted score: 2:1 Actual: Dundee 3:0 #Dundee#Livingston 2026-05-09 14:00 UTC Falkirk vs. Hibernian Predicted outcome: Falkirk❌ Predicted score: 2:1 Actual: Hibernian 1:3 #Falkirk#Hibernian 2026-05-09 19:00 UTC Motherwell vs. Heart Of Midlothian Predicted outcome: Heart Of Midlothian❌ Predicted score: 1:2 Actual: Draw 1:1 #Motherwell#HeartOfMidlothian #Football#ScotlandPremiership

AI match predictions

@ai_match_prediction · Post #11125 · 21.03.2026 г., 09:06

Scotland Premiership🏴󠁧󠁢󠁳󠁣󠁴󠁿 2026-03-21 15:00 UTC Kilmarnock vs. Livingston Predicted outcome: Kilmarnock✅ Predicted score: 2:1 Actual: Kilmarnock 2:0 #Kilmarnock#Livingston 2026-03-21 15:00 UTC Heart Of Midlothian vs. Dundee Predicted outcome: Heart Of Midlothian✅ Predicted score: 2:0 Actual: Heart Of Midlothian 1:0 #HeartOfMidlothian#Dundee 2026-03-21 15:00 UTC Motherwell vs. Hibernian Predicted outcome: Motherwell❌ Predicted score: 1:0 Actual: Draw 0:0 #Motherwell#Hibernian 2026-03-21 15:00 UTC Falkirk vs. ST Mirren Predicted outcome: Falkirk❌ Predicted score: 2:1 Actual: ST Mirren 1:2 #Falkirk#STMirren 2026-03-21 17:45 UTC Rangers vs. Aberdeen Predicted outcome: Rangers✅ Predicted score: 2:0 Actual: Rangers 4:1 #Rangers#Aberdeen #Football#ScotlandPremiership