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

Резултати

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

Пребарај: #adventureawaits

当前筛选 #adventureawaits清除筛选
Auto Life

@revheadcrypto · Post #439 · 05.09.2024 г., 07:03

🚗✨Introducing the New Nissan Patrol & Armada!✨🚙 🌍 Available globally as the Patrol and in the USA as the Armada, these powerful SUVs are equipped with a robust 3.5L turbo V6 engine, delivering an impressive 425 HP and 700 Nm of torque! 💪🔧 (+7% power & +25% torque) paired with a smooth 9-speed automatic transmission. 📏 Built on the recently launched Infiniti QX80 platform, the Patrol has been slightly lengthened and widened while maintaining the same wheelbase. 🛠️ It now offers even more space for passengers, with an additional 145 mm in the third-row legroom, and a cargo capacity ranging from 578 to 2750 liters! 🧳📦 🌄 The all-wheel-drive system features a low range and optional rear differential lock for enhanced off-road capability. For the North American market, check out the rugged Armada Pro-4X variant, complete with air suspension, off-road bumpers, and all-terrain tires! 🌲🛤️ 💰 Prices have been announced only for the UAE, starting at approximately $65,000. Get ready for adventure with the new Nissan Patrol & Armada! 🚀🌟 #NissanPatrol#NissanArmada#SUV#OffRoad#AdventureAwaits#PowerfulPerformance#Auto

Auto Life

@revheadcrypto · Post #629 · 08.11.2024 г., 09:31

🚐✨Introducing the Luxurious Brabus Big Boy 1200 Motorhome!✨🚐 This stunning camper, priced at €1.26 million, measures an impressive 12 meters in length and is designed for a maximum of three residents. 🛏️👨‍👩‍👧 The Big Boy 1200 features several retractable modules that expand the living space during your stay, offering a spacious bedroom and a cozy living area that doubles as a dining room. 🛋️🍽️ In the bedroom, you'll find a full-size bed (160x200 cm), while an additional sleeping space for one person is cleverly located above the driver’s cabin. 💤🛌 Built on a robust three-axle Mercedes-Benz Actros chassis, this motorhome is powered by a 12.8-liter diesel engine that delivers an astonishing 530 hp and 2600 Nm of torque! 💪🚛 Get ready to travel in style and comfort! 🌍❤️ #Brabus#BigBoy1200#LuxuryMotorhome#VanLife#TravelInStyle#MercedesBenz#AdventureAwaits#Auto

Auto Life

@revheadcrypto · Post #569 · 11.10.2024 г., 06:43

🚗💨Introducing the Ford F-150 Raptor Shelby Baja Raptor!💥🔥 Get ready to unleash the power with an incredible 900-horsepower engine upgrade! 💪 The 3.5L V6 EcoBoost now roars at 550 hp, while the 5.2L V8 on the Raptor R delivers a staggering 730 hp with a new supercharger and custom exhaust! 🎉🔧 Key features include: ✨ Enhanced BDS suspension ✨ Massive 37-inch tires ✨ Custom hood with air intakes ✨ Heavy-duty bumpers and extra LED lights ✨ Robust cargo rack for the bed Starting at just $51,995 (excluding the base truck price), this beast is ready to dominate any terrain! 🌍🏞️ #FordF150#Raptor#ShelbyBajaRaptor#OffRoad#Power#TruckLife#AdventureAwaits#CarEnthusiast#Auto