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

Резултати

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

Пребарај: #june4

当前筛选 #june4清除筛选
Hong Kong Democracy Movement

@hkdmovement · Post #7472 · 05.06.2024 г., 03:49

There were police everywhere in Hong Kong as if they were ready for a terrorist attack. But all they were doing was to catch people with a candle on #June4th. #June4 #8964 #tianamensquaremassacre#neverforget1984#hkpolicestate Photos from @ReNews

🕯 六四悼念晚會|英國各地 📍 6 月 4 日,英國多個城市將會舉行六四悼念晚會。 喺呢個重要日子,一齊用燭光紀念歷史、悼念死難者,堅持真相,延續記憶,守護言論與集會自由。 誠邀大家出席所在地區嘅悼念活動,與港人同行,守護良知。 📌 各地活動詳情,請以主辦單位公布為準。 (我哋亦整理咗主要場地嘅資訊,見下一張圖/Story) #六四#六四晚會#六四36周年#移英港人#英國港人#毋忘六四 🕯 June 4 Vigil | Across the UK 📍 On June 4, vigils will be held across various cities in the UK to commemorate the Tiananmen Massacre. We invite all Hongkongers and supporters to join these gatherings — to honour the fallen, defend the truth, and carry the memory forward. 📌 Please refer to the respective organisers for final event details. (We’ve compiled the key locations — check the next image / Story ) #June4#TiananmenMassacre#VigilUK#HongKongersInUK#NeverForget#Democracy *** ✏️有英國國會聯署任務,你簽咗未? 1⃣BNO平權聯署 ✅ 2⃣「外國影響力登記計劃」中 列明中國與香港為「進階級別」聯署✅ ✏️如果有諗法想講,㩒入嚟一齊傾📝 🇬🇧除咗生活,一個仲會講抗爭嘅英國公海。

Hong Kong Democracy Movement

@hkdmovement · Post #8010 · 05.06.2025 г., 04:03

#CCP bans Tiananmen vigil, intensifies crackdown in #HongKong On the 36th anniversary of the Tiananmen Square Massacre, #HongKongPolice deployed heavy forces, detaining at least 12 people, including activists carrying symbolic items. 🔹 2 arrested – A mainland woman* and a local man were detained for failure to produce ID & obstructing police officers. 🔹 10 others taken away – 5 men and 5 women, aged 15 to 69, were detained for "breach of peace", with 3 still in custody. 🔹 CCP’s Erasure of History – The once-massive Tiananmen vigil in Hong Kong is now banned, part of Beijing’s effort to erase the massacre from public memory. #June4#TiananmenMassacre#PoliticalRepression#HumanRights #中共 禁 #六四燭光晚會,#香港 鎮壓升級 在 #六四天安門事件 36周年當天,香港警方 重兵駐守 ,拘捕至少12人,包括持有象徵物的市民及社運人士。 🔹 兩人被捕 – 內地女子及本地男子分別因未能出示身份證及阻撓警務人員被捕。 🔹 十人被帶走 – 5男5女 ,年齡介乎15至69歲 ,因「破壞社會安寧」 被扣查,其中3人仍被拘留。 🔹 中共抹去歷史 – 香港六四燭光晚會已被禁止 ,北京正試圖從公眾記憶中抹去大屠殺。 #天安門事件#政治打壓#人權

Hong Kong Democracy Movement

@hkdmovement · Post #7458 · 01.06.2024 г., 05:13

The 35th anniversary protest and rally for #tianamensquaremassacre is hosting all around the world. Countries include #USA, #Canada#UK, #Japan, #Taiwan, #Netherland, #Australia, and #NewZealand. We urge everyone to gather to protest against tyranny and never forget the day #CCP killed thousands of innocent people who were only seeking for democracy. #tiananmensquare#june4#june41989#tianamensquareprotest