Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
YouTube Downloaders
You can use any of these downloaders to download videos directly from ReVanced/ReVanced Extended
➖➖➖➖➖➖➖➖➖➖
Open Source Downloader
- NewPipe 0.25.1
- NewPipe x Sponsorblock 0.25.1
- Seal 1.9.2
- YTDLnis 1.6.1
- SpotiFlyer 3.6.3
➖➖➖➖➖➖➖➖➖➖
Close Source Downloader
- PowerTube 5.0.3
- DVD 0.1.5
- YMusic 3.7.16
- YouTube Downloader 8.1
➖➖➖➖➖➖➖➖➖➖
- Set downloader to RVX/RV
Join: @ReVanced_MMT
Discussion | Archive
#downloader
SpotiFLAC📱
Mobile port of SpotiFLAC written in Flutter, powered by a Go backend for high performance. Download Spotify tracks in true FLAC from Tidal, Qobuz, & Amazon Music — no ads, no subscription.
- 📥DLs:GitHub
- 🖥Preview
- 🧑💻SourceCode
❤️Follow us:@AndroBusket
📨 Tags: #android#downloader#music
Cobalt
A media downloader website that doesn't piss you off. it's fast, friendly, and doesn't have any bullshit that modern web is filled with: no ads, trackers, or invasive analytics.
paste the link, get the file, move on. it's that simple. just how it should be. You can host your own instance
• bilibili.com & bilibili.tv
• dailymotion videos
• instagram reels, posts & stories
• ok video
• pinterest videos & stories
• reddit videos & gifs
• rutube videos
• soundcloud
• streamable.com
• tiktok videos, photos & audio
• tumblr video & audio
• twitch clips
• twitter videos & voice
• vimeo
• vine archive
• vk video & clips
• youtube videos, shorts & music
cobalt is not affiliated with any services listed above.
this list is not final and keeps expanding over time, make sure to check it once in a while!
https://cobalt.tools
https://github.com/wukko/cobalt
https://status.cobalt.tools
https://github.com/wukko/cobalt/blob/current/docs/troubleshooting.md
Review:
This thing recodes sound to MP3 by default (more lossy distortion on top of whichever lossy codec like AAC the original video uses) which is a very bad idea. Also it processes files and gives its own server links even if the file is something like a YT video that can be downloaded off the original Google servers (with no transcoding whatsoever specified in settings).
And it's all lowercase
#web#video#downloader#yt
FluTube
Multiplatform Youtube video downloader made using flutter.
Features:
- Lightweight and fast
- No Login Required
- Keep your liked videos and comments
- Playlists support
- Download videos, audios and thumbnails
- Ad free forever
- Available for Windows/Linux/Android
- Free libre and open source (FLOSS)
Download - https://github.com/prateekmedia/flutube/releases
https://github.com/prateekmedia/flutube
#yt#YouTube#video#downloader
@foss_Android