Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
#FETUSDT
The price is moving inside a triangle and the price is heavily accumulated and we expect the downward trendline and the triangle to break upwards. If it breaks, we can expect a good rise.
#FETUSDT has reached 9th TP in the VIP HTL signals channel!👍
$304 in profits with a 5% entry and a $1000 deposit!
That's why we call it the "Money Printer" 💴💷💵ACCESS TO MANUAL TRADING for 70usdt/month
💪Rule the market with Propheta AI Signals: ultra-sharp alerts, full-on process automation, and a killer Cornix synergy — your fast track to max profits! GET THE ACCESS TO AI SIGNALS
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#bitcoin#buybtc#btc
#FETUSDT has just reached 9th TP in the VIP HTL channel!!!👍
Using a 5% entry you could've earned $303 with a $1000 deposit
Feels good to be a Propheta VIP, man... 🏖ACCESS TO MANUAL TRADING for 70usdt/month
💰Turn data into gains with Propheta AI Analyzer: deep AI analysis spots trends with surgical precision, tweaks in seconds to your goals, and pair hunting pumps your trading to the next level — this is the evolution of the game! GET THE ACCESS
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#AItrading#eth#trading
👍 This is why we're here!
#FETUSDT has just reached 9th TP in the VIP HTL channel!!!👍
You could've earned $304 with a 5% entry and a $1000 deposit!
Feels good to be a Propheta VIP, man... 🏖ACCESS TO MANUAL TRADING for 70usdt/month
📊Dominate the market with Propheta AI Analyzer: AI uncovers hidden patterns with razor-sharp analysis, adapts on the fly with slick customization, and delivers next-level pair hunting — your edge for strategic supremacy! GET THE ACCESS
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#autotrading#buybtc#tradingindicator
👍 This is why we're here!
#FETUSDT has achieved 9th TP in 6 hours in our VIP HTL channel!
$303 in profits with a 5% entry and a $1000 deposit!
Every day we're on fire! 🔥🔥🔥ACCESS TO MANUAL TRADING for 70usdt/month
💸Turn time into cash with Propheta AI Signals: pinpoint entries and exits, AI-powered automation, and perfect Cornix compatibility — your automated win streak! GET THE ACCESS TO AI SIGNALS
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#buybtc#btc#signalchannel
👆 Propheta living up to its name yet again 🔮
#FETUSDT has achieved 9th TP in our VIP CLUB channel!
Using a 5% entry you could've earned $455 with a $1000 deposit
VIPs getting filthy rich by the day ☺️🤑🤑ACCESS TO MANUAL TRADING for 70usdt/month
👉 We ain't only bragging about those profits, we're publishing the most transparent performance reports you can personally audit!
Come and see for yourself: @propheta_reports
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#cryptobot#CryptoSignal#eth
Now that's trading 👆🔥🔥🔥
#FETUSDT has achieved 9th TP in our VIP HTL channel!
You could've earned $307 with a 5% entry and a $1000 deposit!
Feels good to be a Propheta VIP, man... 🏖ACCESS TO MANUAL TRADING for 70usdt/month
👉 Did you know that our referral partners receive extra discounts, even cumulative with the special offer prices?
START >>> Referral Program
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#bitcoinnews#buyeth#AItrader
👍 This is why we're here!
#FETUSDT has just reached 9th TP in the VIP CLUB channel!!!
Trade took just 23 hours! 👍
With a 5% entry and a $1000 deposit, you could've earned $455!
VIPs getting filthy rich by the day ☺️🤑🤑ACCESS TO MANUAL TRADING for 70usdt/month
👉 We ain't just showing our results, we can show you the results of our VIP subscribers as well! Check them out: @propheta_reviews
Register and get bonuses up to $6,000
Binance | OKX | ByBit👈🏻click!
#eth#cryptoexchange#cryptonews
🚨Candlestick Patterns Detected:
🔨Hammer on #CAKEUSDT (4h)
🔨Hammer on #ASTERUSDT (4h)
====================
⭐Shooting Star on #BTCUSDT (4h)
⭐Shooting Star on #TAOUSDT (4h)
⭐Shooting Star on #2ZUSDT (4h)
⭐Shooting Star on #DOGEUSDT (4h)
⭐Shooting Star on #YBUSDT (4h)
⭐Shooting Star on #FETUSDT (4h)
====================
⚠️Marubozu Bearish on #USDCUSDT (4h)
====================
🚀Marubozu Bullish on #PAXGUSDT (4h)
====================