Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять:
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
😄Practice
➖➖➖➖➖➖
🔘Practice, as a noun, can be the reality of doing something, rather than the theory.
🔜It sounded like a good plan but in practice, it was terrible.
🔜Your idea works in theory. Let's see if it works in practice.
🔘Practice can be used to describe a custom or tradition.
🔜It's common practice to tip taxi drivers and hairdressers in the UK.
🔜Shaking hands before and after a business meeting is good practice.
🔘We can also use practice to describe an activity that we do regularly.
🔜I enjoy football practice because I love football and I see my friends.
🔜I have to go now. I have band practice this evening.
#Practice👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
After many years of inaction, Google has finally released an update for Google Keep ⚹¹ that adds the necessary text formatting functions (i.e. Rich Text Editing or WYSIWYG ⚹²), although not everything — you won’t be able to cross out text. But they are already promising to add version history, which is already something.
Btw even so, "Keep" sucks in terms of functionality and UX, but it's ads-free and fast, so...
#practice
⚹ keep.google.com
100 lines of Go code for … HTTP(S) proxy! Take a look at fast and graceful proxy service based on standard Go http server and client packages 🙂
#development#practice
https://medium.com/@mlowicki/http-s-proxy-in-golang-in-less-than-100-lines-of-code-6a51c2f2c38c
Interesting article about the bufio package in GoLang. How does it work (read, write for different data types) inside of package
#development#practice
https://medium.com/golangspec/introduction-to-bufio-package-in-golang-ad7d1877f762?source=linkShare-b636419a57de-1520074459
Writing Ч ч in cursive can be challenging, but not for you!
🔻Let's watch the video, print out the practice sheet and, shedding tears of despair, practice and move on.
❓Which other letters of the Russian alphabet make you overwhelmingly want to chuck the study of Russian overboard?
📎The pdf file is in the comments
▶️Hard sign tutorial
▶️Сursive letters
#practice
#cursive
😎RCR | Support | Boost
Writing the hard sign (ъ) in cursive can be challenging, but not for us, right?
🔻Let's watch the video, print out the practice sheet and, shedding tears of despair, practise and move on.
❓Which other letters of the Russian alphabet make you overwhelmingly want to chuck the study of Russian overboard?
📎 file is in the comments
▶️Сursive letters
#practice
#cursive
😎 Stay with @learnRCRussian
#Practice
#NUUStudents
⚡️"Yangi O'zbekiston" universitetining bir guruh 1-bosqich talabalari "Inno Technopark"ga tashrif buyurib, uning sharoitlari va imkoniyatlari bilan tanishishgani shaxsan meni quvontirdi.
Negaki, 1-bosqichdanoq amaliy jarayonlarga kirishishlari, kelajakdagi loyihalarda hamkorlik qilishga kelishuvlari💡talabalar uchun juda ham katta maktab bo'lib xizmat qiladi🔥
Izlanish va harakatdan to'xtamang, aziz talabalar❗️
___
⚡️I was personally pleased that a group of first-year students of the "New Uzbekistan" University visited Inno Technopark and gotacquainted with its conditions and opportunities.
Because from the first-year, entering practical processes, dealing to cooperate in future projects will serve as a foundation for students🔥
Bizni kuzatishda davom eting👇
Telegram| Instagram| Facebook| Twitter