Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
Eurasian lynx could be returning to UK countryside after 1,300 year absence, with Wildlife Trust's chief executive insisting they are completely harmless to humans.
Is such a plan another stoke in the fire of the #GreatReset, considering the impact it will have on woodland and livestock, and most significantly, the endangerment to humans? #Agenda2030
https://inews.co.uk/news/environment/eurasian-lynx-reintrodue-rewilding-uk-wildlife-trust-craig-bennett-1330357
And so the globalist agenda continues. Just as the #COVID scam appears to be falling apart, suddenly MSM are discussing gas lines from Russia again, along with possible war with Ukraine. Of course this is just the premise for the next stage, which is the cutting off of gas in the pseudo-climate change agenda. #Agenda2030#GreatReset
https://youtu.be/Hsqks-I19V4
Die 15-Minuten-Städte werden weltweit Schritt für Schritt eingeführt. Die Gesellschaft und Strukturen des öffentlichen Lebens nach und nach angepasst.
Völlige Überwachung und Kontrolle.
#Agenda2030#Agenda2050#NWO
Wahrheit macht frei und Freiheit macht wahr
👉https://t.me/FrMaWa
Denk selbst und informiere Dich 🧩
Nuclear war is exactly what the #globalists want the masses in fear of and distracted by, just as they were with #COVID (which they've miraculously forgot), and perceiving #Russia as an evil threat rather than seeing beyond the concocted narrative and recognising this as yet another orchestrated war. The public falls for condemnations from the West for which it too is guilty, and is led to believe #Ukraine to be an innocent, vulnerable lamb, whilst ignorant that the war is escalating #Agenda2030, which remains unabated as the masses are deceived by smoke and mirrors.
https://www.minds.com/newsfeed/1348255079953600524?referrer=CulturalExile
‼️6G kommt, aber was sie Ihnen nicht sagen, ist, dass es nicht Ihr Telefon verbinden wird, sondern Sie‼️
Die Verbindung des "Internet of Bodies" besteht schon länger und wird nicht erst in 2030 kommen. So sind viele Menschen bereits über tragbare Geräte wie z.B. die Smartwatch damit verbunden.
Quelle:Concerned Citizen
Findest du diese Information wichtig? Dann abonniere unseren Kanal!
👉@LegitimNews
#6G#KI#5GMasten#Testläufe#Agenda2030
People are constantly fooled by being told what they want to hear. #Trump or no Trump, the #globalist agenda is still on course.
#GreatReset#NWO#Agenda2030#WEF
https://www.bitchute.com/video/5iMp8q3nYVCn
✅L'ex dirigente di Pfizer, il dottor Mike Yeadon, sull'Agenda 2030 delle Nazioni Unite:
"Quando le Nazioni Unite, Bill Gates e Klaus Schwab ti dicono che... non viaggerai, non avrai un'auto privata... non ci saranno voli... non possiederai nulla e sarai felice, probabilmente non vivrai nella tua casa... dovresti presumere che siano seri al riguardo."
#vannifrajese#giovannifrajese#piccolelucinelbuio#frajeseofficial
#pfizer#agenda2030#yeadon#covid
Segui il canale ufficiale per rimanere aggiornato
👇👇👇
https://t.me/vannifrajeseofficial
🔥Es ist der Vernichtungs-KRIEG gegen UNS ALLE‼️
💥Nur mit BEFREITEN MS-Medien + SCHULEN gewinnen wir‼️☠️🗽
———————————————
Die Teilnehmerliste des Bilderberg-Treffens 2026
Sie nehmen derzeit die
weiteren Befehle zur
ENTEIGNUNG und VERSKLAVUNG der Menschen
entgegen ...
Auch die deutsche Wirtschaftsministerin Katharina Reiche, sowie andere deutsche Lobbyisten , holen sich dort ihre neuen Befehle ab ❗😡
#Bilderberg
#Bilderberger
#WEF
#Agenda2030
#BlackRock
#Wallstreet
#Zentralbanken
#CityOfLondon
#BIS
@t.me/StuttgartGrundgesetzDemos
TEILEN
Folgt mir auf Telegram
↕️↕️↕️
https://t.me/Kampf_fuer_unsere_Zukunft
Chat-Kanal
⬇️⬇️⬇️
https://t.me/IavYc2SRFdY1OGY6
🚨🌍Digitale Dystopie: Ein investigativer Film über globale digitale Überwachung
Deutsche Übersetzung von Aktuell360 🇩🇪
🎥Dieser Film erklärt das digitale ID-System wie nie zuvor. Vom sozialen Bonitätssystem Chinas bis hin zu den wachsenden digitalen ID-Programmen im Westen.
🔎Digitale Dystopie deckt auf, wie die Bürger dieser Welt in ein Zeitalter der totalen Überwachung hineingezogen werden – und was wir noch tun können, um dies zu verhindern.
👀Ansehen und teilen‼️
#DigitaleDystopie#DigitaleID#Überwachungsstaat#SocialCredit#CBDC#GreatReset#Agenda2030#Totalüberwachung#Aktuell360#Antiilluminaten
🔗Quelle
⚠️EIN PERSÖNLICHER APPELL: AKTUELL360 BRAUCHT EUCH!⚠️
Kanal folgen:
🔥https://t.me/antiilluminaten