Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
🪂Don’t miss this, If you’re holding Ethereum
✅Final Phases of the Berachain Airdrop
🟠Berachain project has been in testnet for a year and is fundamentally a Layer 1 blockchain based on the EVM (similar to Polygon).
💰 raised $140 million from Tier 1 VCs to date.
🗓 Token to launch in Q1 2025, possibly in April 2025.
➡️🔝How to start:
🟢Step 1: Visit the following link:
🔗https://app.stakestone.io/u/vault/detail/bera
🟢Step 2: Connect your wallet and
💥 use this code for a 10% bonus:
69A92
🟢Step 3: If you have extra ETH, take advantage of this opportunity by adding liquidity on the StakeStone platform to maximize your chances of earning two airdrops:
- Berachain Airdrop
- StakeStone Airdrop
🟢Step 4: Deposit ETH, STONE, or WETH to receive beraSTONE tokens.
🔜 ETH withdrawals will be enabled soon, but when you deposit, you’ll receive equivalent beraSTONE tokens, which you can sell anytime on Uniswap to get your ETH back.
⬆️ Holding beraSTONE earns you project-related points for Dolomite_io and KodiakFi.
🪂Official rewards announced so far:
- $STO token rewards
- Berachain rewards via Boyco (a large portion of Bera tokens are allocated to Boyco, which means Berachain airdrop potential).
- Rewards from two projects: KodiakFi and Dolomite_io.
- Additional rewards to be announced.
#Berachain
🤝 Partnership: BearCage X Pirate Frenzy
Thrilled to announce our new partner, BeraCage, the first
Berachain Super Wallet on Telegram! They let users explore the #Berachain Testnet and discover the entire ecosystem right on Telegram.
Users can especially accumulate $BECA tokens by playing the Bear Hunting game, referring friends to BearCage, and much more. The more actions you complete, the greater your chances of earning $BECA and the Berachain token airdrop! 🪂
🐻 Join BearCage's Telegram Mini App now: https://t.me/bearcagebot/bearcage?startapp=nQcep_IflnIi
👉 For more details:https://x.com/PirateClash_HQ/status/1842162175894569068
- - -
Website | Twitter | TG Channel | TG Community | Discord
• Pirate Frenzy (Play-To-Airdrop Mini App on Telegram)
• Pirate Clash (Extension directly playable on Twitter)
Check Your $BERA On TokenPocket! 🐻⛓
Berachain Airdrop Checker is now live on TokenPocket’s Airdrop Zone, allowing you to verify your eligibility with just one click! 🎁🚀
📱https://tokenpocket.pro/en/download/app
💻https://tokenpocket.pro/en/dappstore?category_id=99998&category=Trend
#BERA#Berachain
🐻⛓ Q5! Berachain is now live on TokenPocket.
Berachain is a high-performance EVM-compatible blockchain built on Proof-of-Liquidity consensus.
💙How to create/import a Bera wallet on #TokenPocket?
Guide👉https://help.tokenpocket.pro/en/wallet-operation/how-to-create-a-wallet/berachain
🎈Discover the #BERA Ecosystem with Your TokenPocket! #Berachain
📱https://tokenpocket.pro
💻https://extension.tokenpocket.pro
🐻⛓We now support users to add #Berachain Testnet “Artio” To their TokenPocket Wallet!
The Berachain is an EVM-equivalent L1 built on the Cosmos SDK and powered by Proof of Liquidity.
From now on, you can easily create&import&sync your wallet on berachain on TokenPocket Wallet!
👉https://tokenpocket.pro
#berachain_testnet
Berachain's Infrared Raises $14 Million
Berachain's liquid staking protocol, Infrared, successfully raised $14 million in a Series A token round. The funding aims to support its DeFi initiatives. Read more here: The Block
#DeFi#Berachain#Infrared#Crypto#Investments#Funding#VC
🚨 BREAKING: $117M in assets stolen from @Balancer in the last 2 hours after a major hack!!!
🔹 Assets stolen are across multiple chains: #Ethereum, #Base, #Optimism, #Sonic, #Polygon, #Berachain – mainly in Liquid Staking Tokens (LSTs) of $ETH.
Top 5 stolen assets:
• 7,838 $WETH (~$29.1M)
• 6,841 $OSETH (~$26.8M)
• 4,459 $WSTETH (~$20.1M)
• 2,405 $SFRXETH (~$10M)
• 2,038 $RSETH (~$8.67M)
🔹 The hacker is acting quickly: Converting LSTs into $ETH in real-time!
🔹 Big move: Whale account 0x009, dormant for 3 YEARS, just resurfaced after the exploit and withdrew $7.38M worth of assets from #Balancer!
⚠️ ALERT: If you’re still on #Balancer, secure your funds NOW before it’s too late! 🔐
Follow @spotonchain for more updates about the hack!
https://x.com/spotonchain/status/1985289043383300351
Utah Legislation on Bitcoin Investment Passes
🚀 The Utah House has passed legislation allowing state investment in Bitcoin, moving it to the Senate for further evaluation.
🔗 Read more about the implications of this bill here.
💸 Stablecoin donation company Coala Pay successfully closed a $3.5 million funding round.
🏦 Fed’s Christopher Waller supports stablecoins as vital for USD's reserve currency status.
✨ SEC is reviewing a Solana-ETF application from Grayscale.
📈 Developers of Berachain have launched their mainnet and conducted an airdrop.
🔒 Japan urges Apple and Google to block five crypto exchanges.
#Bitcoin#Stablecoin#CoalaPay#Fed#Stablecoins#SEC#Solana#Grayscale#Berachain#Japan#Crypto#Investment#Legislation#VC#News#USA#Fintech#CryptoExchange#DeFi#Funding#Innovation
Berachain Launches BERA Tokenomics Today
🐻 Berachain introduced BERA tokenomics with a total supply of 500 million tokens.
🐻 Distribution: 48% allocated to the community, including 15.8% for airdrop, 13.1% for future initiatives, and 20% for ecosystem development.
🐻 Eligible for airdrop: early testnet participants, NFT holders, liquidity providers, and Binance HODLers.
🐻 Mainnet launch coincides with the Token Generation Event (TGE) on February 6. More details can be found in ForkLog's article.
#Berachain#Tokenomics#Crypto#Airdrop#NFT#Blockchain#Mainnet#TGE#Community#LiquidityProviders#ETH#Bitcoin#ETF#Finance#Investment#DigitalEconomy#DAO#Kraken#Thailand#DEX