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 слични објави

Пребарај: #bukit

当前筛选 #bukit清除筛选
Bali News

@balinews · Post #386 · 08.04.2025 г., 12:35

🎸Singer and surfer Jack Johnson to give a concert in Bali 📆 Jack Johnson will be coming to Bali in 2025 for a chamber event to be held at Uluwatu Surf Villas on Bukit Peninsula on June 18, 2025 and it will be one performance only. 🎫 Less than 1,000 tickets are expected to go on sale. It costs Rp 2,205,000 for adults and Rp 815,000 for children 5-12 years old. Food and drinks will be available all evening and the event will be completely outdoors. It will be held in all weather conditions. ℹ️ The singer has become known for his soft acoustic music that has become a symbol of the surf culture of the 2000s (many have heard one of his most famous tracks Better Together. Jack Johnson rose to fame after the release of surf movie The September Sessions, where he performed his first songs. @BaliNews #events#concerts#Bukit

Bali News

@balinews · Post #127 · 26.07.2024 г., 10:01

🍊Mandarin Oriental to open new hotel in Bali 🏨 Famous Mandarin Oriental plans to open a luxury resort on the Bukit Peninsula in 2027. The new project will feature 110 rooms, suites and villas, all of which will blend in with the natural surroundings. 🕺 Renowned interior designer Jeffrey Wilkes is involved in the project. He designs luxury hotels and residences. 📍 The location of the resort will be 30 minutes from the international airport. Close to popular tourist areas such as Jimbaran, Uluwatu and Nusa Dua. @BaliNews #places#hotels#goodnews#Bukit

Bali News

@balinews · Post #166 · 06.09.2024 г., 12:01

⛔The canyon to Tanah Barak Beach has been closed to private vehicles 📰 One of Bukit's most photogenic spots near the famous Pandawa Beach, Tanah Barak Canyon, is now off-limits to private vehicles. Tourists will have to walk or take a paid shuttle service. 🏝 Visitors will now be able to enjoy the beauty and tranquillity of Tanah Barak without the passing motorbikes and autos. @BaliNews #trasport#roads#Bukit#beaches

Bali News

@balinews · Post #120 · 19.07.2024 г., 11:02

🛣Details about the construction of a district road in Bukit District authorities are set to solve the road issue in Uluwatu by laying a new district road. Construction of the first section from Siligita village to Sawangan in Nusa Dua district has already started. The original idea was to extend the toll road, which now runs from the airport to Nusa Dua, all the way to Uluwatu. Right now, traffic on the main road jl. Uluwatu is difficult because it is both a hub of commerce and the main thoroughfare of the area, used by everyone from locals to construction vehicles and tour buses. The land acquisition budget for 2024 will be $16 million, with the next one already promised to increase to $19 million. According to an insider in Bali's land office, all consideration of new housing development in the green zone on Bukit is now halted just in time for the land acquisition for the new roads. @BaliNews #roads#roads#authorities#Bukit#Uluwatu#NusaDua