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

Резултати

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

Пребарај: #adt

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

@ai_match_prediction · Post #11790 · 27.04.2026 г., 13:05

Peru Primera División🇵🇪 2026-04-27 20:00 UTC ADT vs. Club Deportivo Los Chankas Predicted outcome: Club Deportivo Los Chankas❌ Predicted score: 1:2 Actual: ADT 4:0 #ADT#ClubDeportivoLosChankas 2026-04-28 00:00 UTC Deportivo Garcilaso vs. FBC Melgar Predicted outcome: FBC Melgar❌ Predicted score: 1:2 Actual: Deportivo Garcilaso 1:0 #DeportivoGarcilaso#FBCMelgar #Football#PeruPrimeraDivisión

AI match predictions

@ai_match_prediction · Post #11253 · 03.04.2026 г., 09:05

Peru Primera División🇵🇪 2026-04-03 16:00 UTC Sporting Cristal vs. UCV Moquegua Predicted outcome: Sporting Cristal❌ Predicted score: 4:0 Actual: UCV Moquegua 1:2 #SportingCristal#UCVMoquegua 2026-04-03 20:00 UTC Alianza Atletico vs. Atletico Grau Predicted outcome: Alianza Atletico❌ Predicted score: 1:0 Actual: Draw 2:2 #AlianzaAtletico#AtleticoGrau 2026-04-03 23:15 UTC Cienciano vs. ADT Predicted outcome: Cienciano✅ Predicted score: 2:1 Actual: Cienciano 3:2 #Cienciano#ADT #Football#PeruPrimeraDivisión

AI match predictions

@ai_match_prediction · Post #11998 · 09.05.2026 г., 13:06

Peru Primera División🇵🇪 2026-05-09 18:00 UTC UCV Moquegua vs. ADT Predicted outcome: UCV Moquegua❌ Predicted score: 2:1 Actual: Draw 2:2 #UCVMoquegua#ADT 2026-05-09 20:15 UTC Atletico Grau vs. Cienciano Predicted outcome: Cienciano✅ Predicted score: 1:2 Actual: Cienciano 1:2 #AtleticoGrau#Cienciano 2026-05-10 01:00 UTC Alianza Lima vs. Sporting Cristal Predicted outcome: Alianza Lima❌ Predicted score: 3:1 Actual: Draw 1:1 #AlianzaLima#SportingCristal #Football#PeruPrimeraDivisión

AI match predictions

@ai_match_prediction · Post #11508 · 14.04.2026 г., 13:05

Peru Primera División🇵🇪 2026-04-14 18:00 UTC UCV Moquegua vs. Juan Pablo II College Predicted outcome: UCV Moquegua✅ Predicted score: 2:1 Actual: UCV Moquegua 3:0 #UCVMoquegua#JuanPabloIICollege 2026-04-14 20:15 UTC ADT vs. Alianza Lima Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Alianza Lima 0:1 #ADT#AlianzaLima 2026-04-15 01:00 UTC Sport Boys vs. FBC Melgar Predicted outcome: Draw❌ Predicted score: 1:1 Actual: FBC Melgar 1:3 #SportBoys#FBCMelgar #Football#PeruPrimeraDivisión

AI match predictions

@ai_match_prediction · Post #11868 · 02.05.2026 г., 13:06

Peru Primera División🇵🇪 2026-05-02 18:00 UTC FC Cajamarca vs. Sport Boys Predicted outcome: FC Cajamarca✅ Predicted score: 2:1 Actual: FC Cajamarca 3:2 #FCCajamarca#SportBoys 2026-05-02 20:15 UTC ADT vs. Atletico Grau Predicted outcome: ADT✅ Predicted score: 2:1 Actual: ADT 1:0 #ADT#AtleticoGrau 2026-05-02 22:30 UTC Cienciano vs. Comerciantes Unidos Predicted outcome: Cienciano✅ Predicted score: 2:1 Actual: Cienciano 1:0 #Cienciano#ComerciantesUnidos 2026-05-03 01:00 UTC Alianza Lima vs. UCV Moquegua Predicted outcome: Alianza Lima✅ Predicted score: 3:0 Actual: Alianza Lima 2:1 #AlianzaLima#UCVMoquegua #Football#PeruPrimeraDivisión

AI match predictions

@ai_match_prediction · Post #11578 · 18.04.2026 г., 13:06

Peru Primera División🇵🇪 2026-04-18 18:00 UTC FC Cajamarca vs. ADT Predicted outcome: FC Cajamarca❌ Predicted score: 2:1 Actual: Draw 2:2 #FCCajamarca#ADT 2026-04-18 20:15 UTC Juan Pablo II College vs. Comerciantes Unidos Predicted outcome: Draw✅ Predicted score: 2:2 Actual: Draw 2:2 #JuanPabloIICollege#ComerciantesUnidos 2026-04-18 22:30 UTC Sport Huancayo vs. Deportivo Garcilaso Predicted outcome: Sport Huancayo✅ Predicted score: 2:1 Actual: Sport Huancayo 2:1 #SportHuancayo#DeportivoGarcilaso 2026-04-19 01:00 UTC Alianza Lima vs. Cusco Predicted outcome: Alianza Lima✅ Predicted score: 1:0 Actual: Alianza Lima 8:0 #AlianzaLima#Cusco #Football#PeruPrimeraDivisión