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

Пребарај: #brighton

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

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

England Premier League🏴󠁧󠁢󠁥󠁮󠁧󠁿 2026-04-11 11:30 UTC Arsenal vs. Bournemouth Predicted outcome: Arsenal❌ Predicted score: 2:1 Actual: Bournemouth 1:2 #Arsenal#Bournemouth 2026-04-11 14:00 UTC Burnley vs. Brighton Predicted outcome: Brighton✅ Predicted score: 1:2 Actual: Brighton 0:2 #Burnley#Brighton 2026-04-11 14:00 UTC Brentford vs. Everton Predicted outcome: Draw✅ Predicted score: 1:1 Actual: Draw 2:2 #Brentford#Everton 2026-04-11 16:30 UTC Liverpool vs. Fulham Predicted outcome: Liverpool✅ Predicted score: 2:1 Actual: Liverpool 2:0 #Liverpool#Fulham #Football#PremierLeague

AI match predictions

@ai_match_prediction · Post #11116 · 21.03.2026 г., 05:05

England Premier League🏴󠁧󠁢󠁥󠁮󠁧󠁿 2026-03-21 12:30 UTC Brighton vs. Liverpool Predicted outcome: Draw❌ Predicted score: 1:1 Actual: Brighton 2:1 #Brighton#Liverpool 2026-03-21 15:00 UTC Fulham vs. Burnley Predicted outcome: Fulham✅ Predicted score: 2:1 Actual: Fulham 3:1 #Fulham#Burnley 2026-03-21 17:30 UTC Everton vs. Chelsea Predicted outcome: Chelsea❌ Predicted score: 1:2 Actual: Everton 3:0 #Everton#Chelsea 2026-03-21 20:00 UTC Leeds vs. Brentford Predicted outcome: Draw✅ Predicted score: 2:2 Actual: Draw 0:0 #Leeds#Brentford #Football#PremierLeague

AI match predictions

@ai_match_prediction · Post #11853 · 02.05.2026 г., 09:05

England Premier League🏴󠁧󠁢󠁥󠁮󠁧󠁿 2026-05-02 14:00 UTC Newcastle vs. Brighton Predicted outcome: Brighton❌ Predicted score: 1:2 Actual: Newcastle 3:1 #Newcastle#Brighton 2026-05-02 14:00 UTC Wolves vs. Sunderland Predicted outcome: Sunderland❌ Predicted score: 1:2 Actual: Draw 1:1 #Wolves#Sunderland 2026-05-02 14:00 UTC Brentford vs. West Ham Predicted outcome: Brentford✅ Predicted score: 2:1 Actual: Brentford 3:0 #Brentford#WestHam 2026-05-02 16:30 UTC Arsenal vs. Fulham Predicted outcome: Arsenal✅ Predicted score: 2:1 Actual: Arsenal 3:0 #Arsenal#Fulham #Football#PremierLeague

AI match predictions

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

England Premier League🏴󠁧󠁢󠁥󠁮󠁧󠁿 2026-05-09 11:30 UTC Liverpool vs. Chelsea Predicted outcome: Liverpool❌ Predicted score: 3:2 Actual: Draw 1:1 #Liverpool#Chelsea 2026-05-09 14:00 UTC Fulham vs. Bournemouth Predicted outcome: Bournemouth✅ Predicted score: 1:2 Actual: Bournemouth 0:1 #Fulham#Bournemouth 2026-05-09 14:00 UTC Brighton vs. Wolves Predicted outcome: Brighton✅ Predicted score: 2:0 Actual: Brighton 3:0 #Brighton#Wolves 2026-05-09 14:00 UTC Sunderland vs. Manchester United Predicted outcome: Manchester United❌ Predicted score: 1:2 Actual: Draw 0:0 #Sunderland#ManchesterUnited 2026-05-09 16:30 UTC Manchester City vs. Brentford Predicted outcome: Manchester City✅ Predicted score: 2:1 Actual: Manchester City 3:0 #ManchesterCity#Brentford #Football#PremierLeague

AI match predictions

@ai_match_prediction · Post #11558 · 18.04.2026 г., 05:05

England Premier League🏴󠁧󠁢󠁥󠁮󠁧󠁿 2026-04-18 11:30 UTC Brentford vs. Fulham Predicted outcome: Brentford❌ Predicted score: 2:1 Actual: Draw 0:0 #Brentford#Fulham 2026-04-18 14:00 UTC Newcastle vs. Bournemouth Predicted outcome: Draw❌ Predicted score: 2:2 Actual: Bournemouth 1:2 #Newcastle#Bournemouth 2026-04-18 14:00 UTC Leeds vs. Wolves Predicted outcome: Leeds✅ Predicted score: 2:1 Actual: Leeds 3:0 #Leeds#Wolves 2026-04-18 16:30 UTC Tottenham vs. Brighton Predicted outcome: Brighton❌ Predicted score: 1:2 Actual: Draw 2:2 #Tottenham#Brighton 2026-04-18 19:00 UTC Chelsea vs. Manchester United Predicted outcome: Draw❌ Predicted score: 2:2 Actual: Manchester United 0:1 #Chelsea#ManchesterUnited #Football#PremierLeague