Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
🔥NEW RELEASE🔥
😁Forging The Guard: Mastering Foundation's Of The Clamp By Giancarlo Bodoni😁
➡️Unlock the secret to dominating your opponent with Giancarlo Bodoni’s "Forging the Guard: Mastering Foundations of the Clamp". As a 2x ADCC champion, training partner of Gordon Ryan, and student of John Danaher, Giancarlo brings you an exclusive BJJ instructional that dives deep into the world of the Clamp Guard
➡️In this series, Giancarlo breaks down the foundational elements of the Clamp Guard, a unique guard that allows for seamless sweeps, submissions, and positional control.
➡️Whether you're a beginner or an experienced practitioner, this instructional will elevate your guard game by showing you how to lock your opponent down, maintain dominant control, and transition fluidly into devastating attacks.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#GiancarloBodoni#BJJFanatics#NewWave#NoGi
💁♀️Buy
💁♀️
😁See the Back Take The Back: Guard Passes To Back Takes by Giancarlo Bodoni😁
➡️See the Back, Take the Back: Guard Passes to Back Takes by Giancarlo Bodoni is the definitive blueprint for turning pressure passing into relentless back-taking offense.
➡️As a 2× ADCC champion, CJI standout, and one of the most technically disciplined athletes to emerge from the legendary Danaher system, Giancarlo has built his game around one thing: getting to the back and finishing—against everyone.
$197😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#GiancarloBodoni#Transitions#NoGi#NewWave
💁♀️Buy
💁♀️
😁Submission Mastery: Omoplata by Giancarlo Bodoni😁
➡️Giancarlo Bodoni — 2x ADCC champion, CJI standout, and elite New Wave athlete under the legendary John Danaher and Gordon Ryan — unveils his groundbreaking system for mastering one of grappling’s most underutilized weapons: the omoplata.
➡️This is not just a submission tutorial. This is a total redefinition of the omoplata for the modern no-gi game — built on elite-level mechanics, control, and finishing options that go far beyond what you thought possible.
$197😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#GiancarloBodoni#Submission#NoGi#NewWave
💁♀️Buy
💁♀️
😁Forging The Guard: Reverse De La Riva By Giancarlo Bodoni😁
➡️Unlock the full potential of your guard game with Forging The Guard: Reverse De La Riva by Giancarlo Bodoni, a two-time ADCC champion and one of the most successful no-gi athletes on the planet.
➡️This comprehensive instructional series takes you deep into the intricacies of the Reverse De La Riva Guard, a position renowned for its versatility, control, and offensive potential
➡️Giancarlo breaks down each detail with clear, concise direction that will help you build a nearly impenetrable guard while simultaneously making you a constant threat from this powerful position.
$197😍$16.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#GiancarloBodoni#NoGi#ReverseDeLaRiva
💁♀️Buy
💁♀️
😁Forging The Guard: De La Riva By Giancarlo Bodoni😁
➡️Unlock the full potential of your guard game with Forging The Guard: De La Riva by Giancarlo Bodoni, a two-time ADCC champion and one of the most successful no-gi athletes on the planet.
➡️This comprehensive instructional series dives deep into the classic De La Riva Guard, a position known for its incredible control, sweeping power, and submission potential.
➡️Giancarlo provides clear and concise direction that will help you elevate your guard to a nearly impassable level while making you a constant offensive threat.
$197😍$16.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#GiancarloBodoni#NoGi#DeLaRiva
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Forging the Guard: Wrestle Ups by Giancarlo Bodoni😁
➡️Giancarlo Bodoni, one of the most dominant grapplers on the planet and a top student of the legendary John Danaher, brings you a game-changing instructional designed to reframe how you think about reversals from the bottom.
➡️In Forging the Guard: Wrestle Ups, Giancarlo reveals how to seamlessly blend traditional BJJ guard positions with low-effort, high-reward wrestle ups—turning common situations into powerful sweeps and takedowns.
̶$̶1̶9̶7̶😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#GiancarloBodoni#WrestleUp#NoGi#NewWave
💁♀️Buy
💁♀️