Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
🇺🇸US soldier arrested for betting on Maduro’s capture — won over $400 000💰
A U.S. Army Special Forces master sergeant, Gannon Ken Van Dyke, has been arrested and charged after allegedly using classified military information to place bets on an online prediction market and win more than $400 000 based on the outcome of a covert operation that captured Venezuelan president Nicolás Maduro.
Van Dyke, who was involved in Operation Absolute Resolve — the U.S. military mission that led to Maduro’s capture on January 3 — reportedly placed about 13 bets on the platform Polymarket, wagering that Maduro would be removed from power. Prosecutors say he used nonpublic knowledge of the operation to make strategic trades that paid off once the raid became public.
Federal authorities have indicted him on multiple counts, including unlawful use of confidential information for personal gain, commodities fraud, wire fraud, and illegal use of classified data. Van Dyke allegedly tried to conceal his identity and the proceeds by using foreign cryptocurrency accounts and requesting deletion of his Polymarket account after the operation was announced.
Officials and lawmakers have condemned the case as a serious breach of trust and a form of insider trading in prediction markets, highlighting concerns about the misuse of secret information for profit.
#Military#DOJ#InsiderTrading
👂More on Trump's Ear ⚠️
Quiver Quantitative | 𝕏
You can track Cantor Fitzgerald's stock portfolio on Quiver:
https://www.quiverquant.com/institutions/CANTOR%20FITZGERALD,%20L.%20P./
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
BREAKING: Cantor Fitzgerald, run by the children of Commerce Secretary Howard Lutnick, just filed a portfolio update.
They bought up huge amounts of Bitcoin, Trump Media stock, and stock in the Chinese company Alibaba.
Full portfolio below.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
You can track Jane Street's stock portfolio on Quiver:
https://www.quiverquant.com/institutions/JANE%20STREET%20GROUP,%20LLC/
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
JUST IN: Jane Street just filed a holdings update.
They added approximately $1B of Bitcoin to their portfolio.
It is now their largest holding.
Full portfolio below.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
You can track Michael Burry's portfolio here:
https://www.quiverquant.com/institutions/Scion%20Asset%20Management,%20LLC/
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
BREAKING: Michael Burry, of "The Big Short" fame, just filed a portfolio update.
He added:
- UnitedHealth, $UNH
- Lululemon, $LULU
- Bruker, $BRKR
- Regeneron, $REGN
- MercadoLibre, $MELI
Track his full portfolio on Quiver.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
We received this data just 15 minutes ago.
Since then:
$UNH +7%
$NUE +6%
$LEN +4%
$DHI +3%
$ALL +0.5% https://twitter.com/QuiverQuant/status/1956086663156830469
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
We expect to have an update on Warren Buffet's portfolio in the next hour.
This might reveal the identify of the mystery stock that he has been buying up.
Turn on post notifications!
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
BREAKING: We just received new data on Senator Dave McCormick's portfolio.
He has up to $5M in Bitcoin, $IBIT.
He also has to $1M in Ethereum, $ETHW.
McCormick sits on the Senate Subcommittee on Digital Assets.
Full portfolio up on Quiver.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading