Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
High hope for another #Arbitrum hype still exists? Because we detect 2 whales that have just accumulated large amounts of $ARB:
✅ Whale 0x6b72 swapped 1.01M $USDT for 607,352 $ARB 4 hours ago. Average price: $1.66
✅ Whale 0x0610 accumulated a total of 2.332M $ARB over the past 2 days. Average price: $1.68
👉 More details: https://twitter.com/spotonchain/status/1648532794103177217
JUST IN :Robinhood launches #Arbitrum based blockchain and tokenized stock trading for European users, offering 24/5 access to over 200 U.S. 🇺🇸 stocks and ETFs.
@spherecryptoofficial1
🚨🚨2,693,961,178 $ARB (~$3.72B) were moved out of #Arbitrum vesting wallet 0x148440 and distributed to 145 addresses.
Address 0x7ff89e received the most at 72,428,835 $ARB ($99.95M), now the 8th largest holder.
The distribution process took place via middle wallet 0x1e7016. 4.17M $ARB (~$5.76M) remained undistributed in it.
Addresses
- Team ARB vesting contract: 0x148440E028565Db5f790fA3fbdbBcF0402A6a289
- Middle wallet: 0x1e7016f7c23859d097668c27b72c170ed7129a10
- Wallet the received the most: 0x7ff89e3c139a30fea7f0d0b079e0d17b95267137
This smart trader, who used to earn $671.6K from trading $GRAIL, started to touch on other #Arbitrum tokens:
- 306.6K $JOE purchased at $0.59 (~$180K). Now staked and worth ~$195K.
- 3.16M$RDNT amassed at $0.4 ($1.27M) from Mar 21-23. Now worth ~ $1.2M
He once earned x2 his investment in $GRAIL by:
✅ Neatly accumulating 342 $GRAIL at only $1,815 (~$621.4K) during market downtime
✅ Sold all $GRAIL at an impressive price of $3,777 on Mar 22 when $GRAIL price surged due to the #Arbitrum airdrop
👉 More details: https://twitter.com/spotonchain/status/1641694153926144000
🚨🚨Arca has sold most of its #Arbitrum related tokens, maybe they are waiting for $ARB launch 🤔🤔
➡️ Swapped 1.6M $RDNT to 712.78K USDT (sell at $0.445 vs buy at $0.274) 10 hours ago
➡️ Swapped 312,000 $SYN for 165.62 $ETH (~$267K) (sell at $0.8 vs buy at $1.21) 4 hours ago
Currently, it clears all $DPX, $RDNT and still holds 20,198 $GMX ($1.6M) in staking and 548,779 $SYN ($510K) in two wallets
Addresses:
0xa66f8Db3B8F1e4c79e52ac89Fec052811F4dbd19
0x23a5efe19aa966388e132077d733672cf5798c03
🔥 VC Arca & traders seem to bet on #Arbitrum token $DPX too!
👉 Arca piled 1,881 $DPX from Feb 17 to 23 at $394 per $DPX (total cost $741.3K).
👉 Trader 0x2761 bought 1,867 $DPX on Mar 1 with 450 $ETH (~$741K) at $396.9 per $DPX. He once made $66.7K by trading $DPX before!
🎉Get ready for an exclusive $SBT Token airdrop!🌟
🤩 Suitbot is a trading bot operating on #ETH and #Arbitrum, aiming to simplify and enhance your DEFI experience.
We will be distributing 1 million tokens to our active community celebrating our token launch! 🫡
Is really easy to participate‼️
🤖 Use our bot to participate.
💬 Join our Telegram for details.
🔗 Telegram group: https://t.me/SuitBotPort
🔗 Twitter: https://twitter.com/SuitBot_TG
Don't miss out on this opportunity! 🚀
With the ongoing hype #Arbitrum narrative, $GMX has become 🔥 than ever before. Let us review some of the top $GMX activites lately!
1. Address 0x426fc1
❗️ Re-amassed 12K $GMX using 526 $ETH (~$994K) on Apr 06 (18hrs ago)
2. Address 0x297903
❗️ Amassed 4.5K $GMX since Mar 07 at $74.3 (~$335K); just got 1.2K $GMX from #Binance at $80.2 (~$100K) on Apr 05
💰 Current holding: 8.6K $GMX (~$677K)
3. Address 0xde32e5
❗️ Amassed 61K $GMX at $76.6 (~$4.7M) on Apr 05 in mid wallet 0xdf42be -> Staked all
💰 Holds 108.7K $GMX (~$8.7M) -> expected profit of $400K
👉 More details: https://twitter.com/spotonchain/status/1644213451001327616
🚀 Just dropped my special Variational Invite Code: OMNIGOLD
https://omni.variational.io/?ref=OMNIGOLD
Use it → get Silver tier on Omni for 90 days instantly (better points multiplier + loss refund odds)!
Zero-fee perps DEX on #Arbitrum. Farming $VAR #airdrop just got easier 🔥
Connect wallet & sign up now!
🪂#Airdrop event for #Arbitrum💙
🏃 First come first served 🏃
🏆 Airdrop Portal 👉https://arb-claim.kepler.homes?code=71D03A
💙 Invitation code: 71D03A
A total of 550,000 addresses are eligible for #airdrop and 5 types of AirDropbox with different scarcity can be issued.