@sgmrt · Post #1703 · 18.04.2023 г., 08:37
[CCL] Train service is resuming progressively. Free regular buses are still available btw #BuonaVista and #HarbourFront. - SMRT
Hashtags
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
Пребарај: #harbourfront
@sgmrt · Post #1703 · 18.04.2023 г., 08:37
[CCL] Train service is resuming progressively. Free regular buses are still available btw #BuonaVista and #HarbourFront. - SMRT
Hashtags
@sgmrt · Post #2287 · 14.03.2025 г., 11:34
[CCL] CLEARED: Fault cleared trains are running normally between #HarbourFront, #MarinaBay and #DhobyGhaut. - SMRT
@sgmrt · Post #2286 · 14.03.2025 г., 11:34
[CCL] UPDATE: Fault cleared trains are progressively returning to normal between #HarbourFront, #MarinaBay and #DhobyGhaut. Train service is still available. - SMRT
@sgmrt · Post #2285 · 14.03.2025 г., 11:14
[CCL] UPDATE: Fault cleared trains are progressively returning to normal between #HarbourFront, #MarinaBay and #DhobyGhaut. - SMRT
@sgmrt · Post #2284 · 14.03.2025 г., 11:05
[CCL]: Additional 15 mins train travel time between #HarbourFront, #MarinaBay and #DhobyGhaut due to a signal system fault. - SMRT
@sgmrt · Post #1912 · 28.04.2024 г., 22:34
[CCL] UPDATE: Additional 30mins train travel time between #Bishan and #one-north due to a train fault. Free Regular bus service is available between #Bishan and #HarbourFront. You may also use alternative lines to travel to your destination. - SMRT
Hashtags
@sgmrt · Post #1911 · 28.04.2024 г., 22:34
[CCL] UPDATE: Additional 30 mins train travel time between #Bishan and #one-north due to a train fault. Free Regular bus service is available between #Bishan and #HarbourFront. We apologise for this delay to your journey. - SMRT
Hashtags
@sgmrt · Post #1702 · 18.04.2023 г., 08:23
[CCL] Due to a power fault, please add 20 minutes additional train travel time btw #KentRidge and #Harbourfront. Free regular buses are available btw #BuonaVista and #Harbourfront. - SMRT
@sgmrt · Post #1913 · 28.04.2024 г., 22:39
[CCL] UPDATE: Additional 30 mins train travel time between #PayaLebar and #one-north due to a train fault. Free Regular Bus Service is available between #PayaLebar and #HarbourFront. Bridging bus service is available between #PayaLebar and #BuonaVista. - SMRT
@sgmrt · Post #2183 · 15.12.2024 г., 16:44
[CCL] UPDATE: Due to signaling fault, please expect additional 30 mins travelling time btwn #Farrer Road and #HarbourFront. Free regular bus services are available between #Botanic Gardens and #HarbourFront. - SMRT
Hashtags
@sgmrt · Post #1910 · 28.04.2024 г., 22:19
[CCL] UPDATE: Additional 30mins train travel time between #HollandVillage and #PasirPanjang due to a train fault. Free Regular Bus Service is available between #Bishan and #HarbourFront. We apologise for this delay to your journey. - SMRT