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

Резултати

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

Пребарај: #binourtissues

当前筛选 #binourtissues清除筛选
NEA Singapore

@NEASingapore · Post #154 · 22.01.2021 г., 10:50

Have you been returning your trays and binning used tissues? A large majority of people surveyed agreed that litter left behind poses a public health risk. However, whilst 90% felt that diners should clear their tables after eating at public dining places, the average tray return rate at most hawker centres is only around 30%. View key findings of the survey at https://www.nea.gov.sg/media/news/news/index/vast-majority-surveyed-feel-that-patrons-should-be-required-to-clear-their-tables-after-eating-at-public-dining-places We can do more to keep #OurHawkerCentres clean and safe for everyone! #ReturnOurTrays#BinOurTissues

NEA Singapore

@NEASingapore · Post #144 · 28.12.2020 г., 05:22

Phase 3 of Re-opening commences today. To accommodate the increase in group size of up to 8 persons, markings on seats and tables at the dining areas of hawker centres have been revised. While we bond over our favourite hawker food, let’s also #ReturnOurTrays and #BinOurTissues. #OurHawkerCulture is not just about the heritage, great food and bustling ambience – it is also about how it brings people from all walks of life together. Let’s keep #OurHawkerCentres clean and safe for everyone 😊 Access control and interim fencing at more markets will also be removed, details at https://www.nea.gov.sg/media/news/news/index/phase-3-of-re-opening-hawker-centres-and-markets

NEA Singapore

@NEASingapore · Post #69 · 20.06.2020 г., 03:30

We are all looking forward to dining in again at our favourite places. Let’s not forget good dining habits at #OurHawkerCentres to mitigate the spread of COVID-19! #BinOurTissues & #ReturnOurTrays, to keep the table clean for the next user and reduce the risk of disease transmission to cleaners and other members of the public. Eat from your tray, and don’t leave behind soiled tissues or wet wipes on dining tables. #FightCOVID19#SGClean

NEA Singapore

@NEASingapore · Post #67 · 17.06.2020 г., 12:55

Don’t leave your used tissues or wet wipes behind when dining at #OurHawkerCentres! It is important to dispose of used tissues or wet wipes which can be highly contaminated, to #FightCOVID19, especially as we resume our activities gradually. From 19 Jun when dining-in resumes, Safe Distancing Ambassadors at hawker centres and coffeeshops will be on hand to remind patrons to be socially responsible and observe personal hygiene. Let’s all do our part to keep ourselves and those around us safe. https://go.gov.sg/nea17jun20-hygieneathcs-toilets #BinOurTissues#ReturnOurTrays#SGClean#KeepSGClean

NEA Singapore

@NEASingapore · Post #73 · 02.07.2020 г., 00:30

Let’s remember to stay at least a metre apart from each other. We wouldn’t want all the effort and resources of the past few months to go to waste. Dining in at #OurHawkerCentres? Let’s not forget to #ReturnOurTrays and #BinOurTissues after enjoying the meal! #SGUnited#SafeDistancing#FightCOVID19