Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
¡New build available!
#DerpFest | #Official#diting
Device:Xiaomi 12T Pro | Redmi K50 Ultra
Sha256SUM:fcc1f00c1b95a94db388c5acadbb
Build Date:2024-02-22
Downloads:
Link |Mirror
Changelog:
- Reimplement Custom headers feature from Bootleggers
- Allow to skip confirmation in biometric auth dialog
- Tint app name in notifications with app icon color
- Extend showing Ambient instead of fully waking to single tap gesture
- Fix wakeup and long-press actions of assistant key
- Gesture nav: Remove timeout setting and minor improvements
- Few layout fixes for advanced reboot options
- Add faster qs tile animation speeds
- Fix premature short-circuit on end spring anim
- Fix crash on notification icon contrast calculation
- Upgrade blobs to HyperOS CN miui_DITING_OS1.0.24.1.8.DEV_8704513c97_14.0
- adjust vibration
- upgrade kernel and modules to OS1.0.2.0.ULFCNXM Thnks to @Mohammadnt96
Notes
• Gapps are included
• Remebering, Don't report bugs without logs.
• CTS pass by default
By @TeamMEX_XDA
Donate PayPal
¡New build available!
#DerpFest | #Official#diting
Device:Xiaomi 12T Pro | Redmi K50 Ultra
Sha256SUM:1ec96f10def7980fae0eb6ed2af22900e4c5138dc70a612e7c5d89fcbb0a2a48
Build Date:2024-02-03
Downloads:
Link |
Changelog:
- Fixed miui camera issues (Still cant be open photos from the app use google photos)
- Implement UDFPS animations (inside theme picker -> lockscreen)
- Adjust udfps size
- fix issue where rebooting to twrp or similar the device panics to fastboot
- Fixed eSIM issues (now eSIM should work without more problems)
- Implement parallel space
- sync more stuff from derp
- Change vibration effects thnks to
@Mohammadnt96
Notes
• Gapps are included
• Remebering, Don't report bugs without logs.
• CTS pass by default
By @TeamMEX_XDA
Donate PayPal
¡New build available!
#DerpFest | #Official#diting
Device:Xiaomi 12T Pro | Redmi K50 Ultra
MD5SUM:97bed4a62116ae1abcf4211b3ac9a5a2
Build Date:2023-12-20
Downloads:
Link |
Changelog:
- Merge QPR1 (aka December security patch)
- Remove OOS style clear all button toggle due to QPR1 conflicts
- Switch to Yaap's impl for battery icon customizations
- Switch to AOSP themepicker to fix wallpaper apply button and other small issues
- Add DerpFest Updater (based on Lineage updater)
- Fix for Faceunlock needing a reboot to work after registering a face model
- Add optional bouncer user switcher toggle
- Add option to display data disabled indicator icon
- DerpSpace: Add a secure section to quick settings
- DerpLauncher:Import Lawnicons
- Update Gramophone prebuilt
- Switch to ARMv9 and Cortex-A510 optimizations
- Sepolicy enforcing
Notes
• Gapps are included
• FOD Not working on gtx8_spi touch screen
• Remebering, Don't report bugs without logs.
• CTS pass by default
By @TeamMEX_XDA
Donate PayPal
¡New build available!
#DerpFest | #Official#diting
Device:Xiaomi 12T Pro | Redmi K50 Ultra
MD5SUM:5b8c26aeef4d9f418db9c4cbdfe48833
Build Date:2023-11-25
Downloads:
Link |
Changelog:
- Fixed performance degradations
- Fixed dolby atmos issues
- Update props from stock
- Reset FOD blobs to DITING_V14.0.10.0.TLFCNXM
- Dont allow to run foreground process con CPU7
Notes
• Gapps are included
• FOD Not working on gtx8_spi touch screen
• Remebering, Don't report bugs without logs.
By @TeamMEX_XDA
Donate PayPal
¡New build available!
#DerpFest | #Official#diting
Device:Xiaomi 12T Pro | K50 Ultra
MD5SUM:166b3c96ba79207e8e2295621661c3aa
Build Date:2023-11-22
Downloads:
Link |
Changelog:
- FOD issue should be fixed now
- fixed battery styles
- now fod is called again biometrics and not pixel imprint
- fixed some crashed on derpspace (general is still empty)
- Sync with last derp source
Notes
• Gapps are included
• Fod not working on gtx8_spi devices
• Remebering, Don't report bugs without logs.
Know bugs:
- Screen record
- Fod on gtx8_spi
- sepolicy permissive (not a bug but u know some call it as bug)
By @TeamMEX_XDA
Donate PayPal