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

Резултати

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

Пребарај: #umar

当前筛选 #umar清除筛选

I was searching on Telegram and saw that Wahhabis (#ISIS) are very active on Telegram and have many channels. Many Muslims follow #Wahhabism. The center of this deviant thinking is Takfiri in Saudi Arabia. Arab countries have a small population, but they have a lot of oil resources. They sell black gold (oil) at a low price and buy goods made with oil at a high price. Consumerism; Imitation of the West is common among Muslims. Due to the prevalence of #Zionist media, ignorance and superstitions have spread in Islamic countries. Their governments are kingdoms instead of democracy. Their rulers only leave power when they are dead. Meanwhile, in the Quran, friendship between Muslims and Jews and Christians is forbidden; Arab rulers are friends with non-Muslims and dance with them. But they draw swords against Muslims and kill their brothers. This deviant thinking has its roots in the first century of Hijri. #Abu_Bakr and #Umar also harassed the Prophet's family. In the Holy Quran, Surah Shuri, God said, O group of Muslims, be kind to the family of the Prophet, but the Muslims massacred the entire family of the Prophet. The wild thinking that can be seen in Muslim countries today is the result of the coup by Abu Bakr and Omar against the successor of the Prophet (Ali). Terrorists such as #bin_Salman bin Laden, Saddam and #Erdogan are introduced as the top personalities of the Islamic world. Hypocrites who secretly cooperate with the Zionists but attack the Muslims of Palestine, Iraq, Lebanon, Syria, Iran and Yemen. The governments of #Saudi_Arabia, #Turkey, Bahrain, Kuwait, Qatar, Egypt, Jordan, Pakistan, and Afghanistan by promoting deviant ideas such as the Muslim Brotherhood and Wahhabism; Deobandi fight with countries that want to be independent (Yemen, Palestine, Syria, Iraq and Iran). People walking down the street suddenly explode. Because Sunnis blow themselves up among Muslims to go to heaven!!!! May God curse Israel, US, and their supporters. Because they blackened the face of Islam and presented the Islam desired by the United States. https://t.me/YediotNewsChat