Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
Lookonchain | ꘜ
A newly created wallet (0xa523) deposited 23.52M $USDC into #Hyperliquid to buy 466,421 $HYPE ($21.5M) and 2.16M $Fartcoin ($2.12M) in the past 7 hours.
https://hypurrscan.io/address/0xa5232e97b4ded3d2EF25Be059c3489e61Be475Aa
A newly created wallet deposited $3.18M $USDC into #HyperLiquid and opened an $ETH long position with 20x leverage.
The whale is likely to increase the position or open a new one.
@Runlifenick_fx✅
A mysterious whale wallet 0x579f has deposited $2.91M USDC into #Hyperliquid over the last 48 hours — taking massive leveraged bets across three major assets:
• Short 232 BTC (~$25M)
• Short 5,810 ETH (~$22.7M)
• Long 44.79M ENA (~$21.3M)
That’s a combined open position of nearly $70M, signaling a strong rotation from majors to ENA.
https://hypurrscan.io/address/0x579f4017263b88945d727a927bf1e3d061fee5ff
A whale recently created a new wallet (0xb0a0) and deposited $4 million USDC into #Hyperliquid, signaling a major move to accumulate $HYPE.
So far, the wallet has purchased 58,778 $HYPE worth approximately $2.89 million.
https://hypurrscan.io/address/0xb0a0f97898682E3c0A83633DF67E67249d6B12fa
As $UNI is trading at ~$10, a whale holding a $UNI long position with 10x leverage currently has a floating profit of $3M on #HyperLiquid.
The whale also has long positions on $ETH (25x), $BTC and $SOL with 20x leverage, with floating profit of $9.38M.
Overall, the whale is making $31.9M.
https://hyperbot.network/trader/0x9263c1bd29aa87a118242f3fbba4517037f8cc7a
A newly created wallet "0x01f" deposited 242 $ETH into #HyperLiquid to sell, then opened a 3,286.46 $ETH short position with 20x leverage valued at ~$7M.
https://hyperdash.com/address/0x01f135c734b4aae018ebf4e7995c560a38422e50
https://x.com/OnchainLens/status/2041019716492537964
Follow @onchainlens for more onchain updates
After 5 months, a whale deposited $1M $USDC into #HyperLiquid and opened a 20,000 $BRENTOIL long position with 20x leverage.
Previously, the whale has made over $12.44M.
https://hyperbot.network/trader/0x9aB1c356E6Af86361446497FCe954B3CDF940206
https://x.com/OnchainLens/status/2040359551682412700
Follow @onchainlens for more onchain updates
A wallet deposited $2.25M $USDC into #HyperLiquid and opened a 2,271.55 $GOLD ($10M) long position with 10x leverage. https://hyperbot.network/trader/0x06a33efba1ea066af486d3d8b89eea896ec1cf69 https://x.com/OnchainLens/status/2036242636579938809 Follow @OnchainLens…
Machi deposited another $300K USDC into #HyperLiquid to increase his $ETH (25x) long position.
Earlier, Machi partially closed the position at a loss to avoid liquidation.
Machi’s loss is now over $31.29M.
https://hyperbot.network/trader/0x020ca66c30bec2c4fe3861a94e4db4a498a35872
https://x.com/OnchainLens/status/2039617823027425483
Follow @onchainlens for more onchain updates
A newly created wallet deposited $9.6M $USDC into #HyperLiquid and opened a $CL long position with 20x leverage. The position is still increasing. https://hyperbot.network/trader/0x9D32884370875f2960D5CC4b95Be26687d69Aff5 https://x.com/OnchainLens/statu…