Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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🔥
😁Pressure Drop: Close Range Passing by Brian Glick😁
➡️Pressure Drop: Close Range Passing is the latest instructional from Brian Glick—one of the most respected teachers in modern jiu-jitsu and a long-time black belt under John Danaher.
➡️Known for his meticulous, methodical, and deceptively simple approach to the art, Brian breaks down the close-range passing game into clear, repeatable steps that any grappler can immediately apply.
$197😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#Passing#NoGi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Dynamic Guard Passing: Inside Position by Brian Glick😁
➡️Unlock the secrets of high-level standing guard passing with one of the most respected minds in Brazilian Jiu-Jitsu, Brian Glick, black belt under the legendary John Danaher.
➡️This instructional zeroes in on how to pass while standing, using the inside position to dominate exchanges, neutralize leg entanglements, avoid leg locks, and shut down wrestle-up attacks
$197😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#Passing#NoGi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Pressure Drop Dynamic Guard Passing: Outside Position by Brian Glick😁
➡️Unlock the secrets of high-level guard passing with Pressure Drop Dynamic Guard Passing: Outside Position by Brian Glick, a black belt under the legendary John Danaher.
➡️Renowned for his ability to distill complex techniques into clear, accessible instruction, Brian brings his signature clarity and precision to this must-have series.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#NewWave#NoGi#Passing
💁♀️Buy
💁♀️
🐈⬛NEW RELEASE
🐈⬛
🐈⬛Under Control Transforming Your Closed Guard by Brian Glick
🐈⬛
🐈⬛In Under Control: Transforming Your Closed Guard, Brian Glick delivers a complete system for building a closed guard that is tight, efficient, and relentlessly effective—regardless of size or strength
🐈⬛This is not a collection of random moves—it’s a carefully structured approach to controlling, breaking, and submitting opponents from one of jiu-jitsu’s most important positions.
$197
🐈⬛$14.99
🐈⬛
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#Transitions#NoGi#NewWave
🐈⬛Buy
🐈⬛
🔥NEW RELEASE🔥
😁Knee Lever Masterclass by Brian Glick😁
➡️The Knee Lever Masterclass from Brian Glick, a John Danaher black belt and one of BJJ Fanatics’ best-selling instructors, is your complete system for turning one of Jiu-Jitsu’s most underrated techniques into a powerful, all-position weapon
➡️Known for his world-class instruction, clear communication, and simple, effective systems, Brian once again delivers an instructional packed with precise details and universal concepts that make complex ideas easy to apply.
$197😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#Sweeps#NoGi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Crucifix Masterclass by Brian Glick😁
➡️A direct student of legendary coach John Danaher, Brian breaks down the crucifix in a methodical, accessible system designed to transform this powerful position into a high-percentage part of your game.
➡️Instead, it leverages advanced, submission-based control points that create tremendous vulnerability in your opponent while giving you near-total dominance.
̶$̶1̶9̶7̶😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#Submission#NoGi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Only Way Out: Dynamic Back Escapes By Brian Glick😁
➡️Unlock your path to freedom with Only Way Out: Dynamic Back Escapes by Brian Glick, one of the most sought-after instructors at BJJ Fanatics. Brian’s teaching ability is renowned for breaking down complex techniques into easily digestible steps, helping practitioners at all levels of Brazilian Jiu-Jitsu (BJJ) master the art of escaping back control.
➡️Whether you're a white belt or a seasoned competitor, Brian's step-by-step breakdowns will give you the tools to confidently escape back control in any situation
➡️This instructional covers a variety of dynamic back escapes, teaching you how to stay calm under pressure and develop the instincts needed to reclaim control.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#BJJFanatics#NewWave#NoGi#Danaher
💁♀️Buy
💁♀️