TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #32 · 7 фев.

Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять: 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

Резултати

Пронајдени 302 слични објави

Пребарај: #newindia

当前筛选 #newindia清除筛选
MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13379 · 14.04.2025 г., 06:44

From Runways to Sky-High Stats ✈️ India’s passenger traffic soars 143% — a testament to rising infrastructure, connectivity & progress! #NewIndia

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12790 · 05.06.2023 г., 13:02

Exciting opportunity to test your knowledge and contribute to nation-building 📝🧾 Take part in the '9 Years of Seva, Sushasan aur Garib Kalyan' Mahaquiz 2023 and celebrate the progress made towards #NewIndia. Visit: https://quiz.mygov.in/quiz/9-years-seva-sushasan-aur-garib-kalyan-mahaquiz-2023/

Hashtags

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #12691 · 10.05.2023 г., 08:52

Modern stations for a modern India! With state-of-the-art facilities & world-class amenities, the upgraded railway stations will be a reflection of #NewIndia's progress

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12283 · 09.03.2023 г., 07:09

Capture the transformation of #NewIndia with your lens! Participate in contest and get a chance to win exciting cash prizes Visit: https://innovateindia.mygov.in/beneficiary-videos/

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12181 · 27.02.2023 г., 11:14

Show #NewIndia with your lens! Participate in "Inviting Videos of Transformative Impact" and highlight the benefits received from particular schemes Visit: https://innovateindia.mygov.in/beneficiary-videos/

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12143 · 23.02.2023 г., 15:11

Calling all creative minds to compose a Jingle for the 100th episode of Mann Ki Baat Participate & get a chance to make your jingle remain in the minds and hearts of #NewIndia Visit: https://secure.mygov.in/task/compose-jingle-100th-episode-mann-ki-baat/

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12142 · 23.02.2023 г., 14:10

Show #NewIndia with your lens! Participate in "Inviting Videos of Transformative Impact" and highlight the benefits received from particular schemes Visit: https://innovateindia.mygov.in/beneficiary-videos/

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #12118 · 20.02.2023 г., 09:09

Here's a platform to showcase the #NewIndia Share your Before and After videos and describe how a particular scheme of government has benefited you Visit: https://innovateindia.mygov.in/beneficiary-videos/

Hashtags

MyGov Newsdesk

@mygovcoronanewsdesk · Post #11479 · 29.11.2022 г., 08:10

Are you the next best-selling author of #NewIndia? We are looking for you! Apply for YUVA 2.0 and get mentorship, stipend and much more! Know more here : innovateindia.mygov.in/yuva/

Hashtags

123•••10•••20•••2526
ПретходнаСтраница 1 од 26Следна