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

Резултати

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

Пребарај: #viksitbharat

当前筛选 #viksitbharat清除筛选

#MyGov पल्स - सिटीजन कनेक्ट पाक्षिक न्यूज़लेटर के इस अंक में 2023 में भारत की ऐतिहासिक उपलब्धियों और #ViksitBharat की दिशा में प्रगति से संबंधित उपलब्धियों को जानें। पूरा पढ़ें: https://static.mygov.in/static/s3fs-public/mygov_170349057782937911.pdf

जिन मुद्दों को दशकों तक किया गया नजरअंदाज, प्रधानमंत्री नरेंद्र मोदी के नेतृत्व में बीते 10 वर्षों में उनका हुआ कायाकल्प। आइए देखें... #PMModi#NewIndia #ViksitBharat

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13292 · 25.10.2024 г., 14:36

We got this, and #ViksitBharat is all about it! Don’t miss this week’s #FridaysAtMyGov to see young minds sharing their vision for #NewIndia 2047 and how, with government support, they are flexing their skills to build the future they want To watch the full episode, visit: https://www.youtube.com/watch?v=mmZFDtR_LrE

सहकारिता - विकसित भारत की असली ताकत! खेती, डेयरी, बैंकिंग, बीज, निर्यात और सेवाओं तक; सहकारिता का मॉडल किसानों, कामगारों और ग्रामीण भारत को सशक्त बनाकर ‘सहकार से समृद्धि’ की राह को मजबूत कर रहा है। आइए इस 🧵 द्वारा जानें: https://x.com/i/status/2030890080014156147 #SahkarSeSamriddhi#ViksitBharat

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13316 · 08.01.2025 г., 16:37

This week, MyGov India hosts Soumitra Dutta, professor at the University of Oxford and author of 'From Gridlock to Growth: How Leadership Enables India's Pragati Ecosystem to Power Progress'. Explore how PRAGATI has transformed the delivery of major infrastructure projects and propelled India’s progress to new heights. Don’t miss this opportunity to gain valuable insights into the transformative journey of #NewIndia! Watch the full episode: https://youtu.be/VTp4fv1H31k #PRAGATI #ViksitBharat

भारत की डिजिटल क्रांति की ऐतिहासिक छलांग! अगस्त में UPI लेनदेन ने पहली बार 20 अरब का आँकड़ा पार किया #DigitalIndia#UPI#ViksitBharat

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13331 · 24.01.2025 г., 17:40

All aboard the future of rail travel!🚆 This #FridaysAtMyGov, experience the engineering marvel #VandeBharat Express, now connecting Delhi to Srinagar under the visionary #MakeInIndia initiative. Ready to tackle snow, designed for comfort, and built for innovation, it's a symbol of #ViksitBharat in motion. Watch the full video now: https://www.youtube.com/watch?v=LmufFHQY2gc #NewIndia

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13330 · 23.01.2025 г., 03:40

NRIs aren’t just Indians abroad—they’re Bharat’s global power. #PravasiBharatiyaDivas celebrates this unbreakable bond. A day that honours the spirit of NRIs, proving that distance can never weaken their connection with Bharat Watch their inspiring journeys and hear their views on Bharat’s global rise under PM Narendra Modi’s visionary leadership 🎥 To watch the full video, visit: https://youtu.be/-g65oAFX5Yg?si=n1XUY7r1c66BnkRs #ViksitBharat #NewIndia #PBD2025

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13312 · 06.01.2025 г., 12:35

5 Crore Voices. 5 Crore Dreams. 5 Crore Saathis. MyGov.in, launched by PM Narendra Modi, has achieved the incredible milestone of reaching 5 crore subscribers! 🎉 Thank you to every Saathi for being a part of this vibrant community! Let's continue to engage, inspire, and shape a #ViksitBharat together. #5CroreSaathis #MyGovSaathis #NewIndia

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13238 · 09.08.2024 г., 05:50

'करेंगे और कर के रहेंगे' विकसित भारत का संकल्प! On August 9, 1942, we united with a powerful resolve for freedom. #QuitIndiaMovement#UnityInStrength#TransformingIndia#ViksitBharat

MyGov Newsdesk

@MyGovCoronaNewsdesk · Post #13284 · 27.09.2024 г., 16:09

Get ready for another thrilling episode of Fridays At MyGov! Join us as we take you inside the cutting-edge Namo Bharat Rapid Train, redefining travel with its air-conditioned, secure, and modern features. It's not just a ride—it's an experience of convenience and innovation! Watch the full episode: https://www.youtube.com/watch?v=2DOooLw01bo Stay tuned for more episodes celebrating Viksit Bharat. #FridaysAtMyGov#ViksitBharat#NamoBharat#RapidRail

12
ПретходнаСтраница 1 од 2Следна