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

Пребарај: #dreamcar

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

@revheadcrypto · Post #206 · 31.07.2024 г., 08:35

🚗✨ Introducing the stunning Pagani Utopia Roadster! 🌟 This masterpiece trades its traditional roof for a removable panel featuring a sleek glass insert. 🪟 For those who prefer a classic touch, there’s an alternative fabric top that neatly stores in its own case. 🎒 With no need for extra reinforcement, the Utopia's inherent strength shines through in this exquisite design. 💪 Under the hood, this beauty packs a powerful punch with an 864-hp V12 engine from Mercedes-AMG! 🔥💨 Get ready to own this automotive marvel for a cool €3.1 million! 💰 #PaganiUtopia#Roadster#Supercar#Auto#CarEnthusiast#DreamCar#ExoticCars#Pagani

Auto Life

@revheadcrypto · Post #499 · 17.09.2024 г., 05:52

🚙✨For Sale: Brabus 900 XLP!✨🚙 Get ready to own a masterpiece! This exclusive pickup, built on the Mercedes-AMG G 63 platform, boasts a staggering 900 horsepower and only 10 units produced! 🚀 📍Mileage: 3,375 km 💰Price: Nearly $1 million Under the hood, it features a custom-built engine based on the stock V8, with an increased displacement of 4.5 liters, custom turbocharging, and upgraded components for unmatched performance! 🔥 #Brabus900XLP#LuxuryCars#ForSale#SuperPickup#CarEnthusiast#ExoticCars#MercedesAMG#DreamCar#Auto

Auto Life

@revheadcrypto · Post #618 · 31.10.2024 г., 13:23

🚗💨Unleash the Beast: 1600 HP Lamborghini Aventador SVJ!🦙🔥 For those who crave power and performance, Underground Racing Motors is offering a jaw-dropping 1600-horsepower Lamborghini Aventador SVJ for just $1.7 million!💰✨ Originally launched over six years ago, the Aventador SVJ boasts a naturally aspirated 6.5L V12 engine producing 770 HP and 720 Nm of torque. But with the magic of twin-turbocharging and expert tuning, this beast can roar up to an astonishing 1600 HP when fueled with race gas! 🏁💥 On regular gasoline, it still impresses with 1250 HP! #Lamborghini#AventadorSVJ#UndergroundRacing#Supercar#CarEnthusiast#LuxuryCars#TurboPower#Hypercar#DreamCar#Auto

Auto Life

@revheadcrypto · Post #418 · 01.09.2024 г., 10:09

🚗✨For Sale: Aston Martin Vanquish!✨🚗 This stunning grand tourer isn't just any car; it was featured in a promotional photoshoot for the James Bond film "Die Another Day" starring Pierce Brosnan! 🌟 🔹Power: 460 HP 🔹Mileage: Over 60,000 km 🔹Price: Up to $100,000 Don't miss your chance to own a piece of cinematic history! 🎬💎 #AstonMartin#Vanquish#JamesBond#DieAnotherDay#LuxuryCars#CarForSale#BondCar#DreamCar#Auto

Auto Life

@revheadcrypto · Post #77 · 11.07.2024 г., 08:24

🏎 Get your hands on a piece of history! 🌟 Rare Lamborghini Countach LP400 up for auction! Previously owned by musician Rod Stewart. Only around 150 LP400 Countach models were ever produced by Lamborghini, featuring a 3.9-liter V12 engine with 370 horsepower. Rod Stewart was the proud first owner of this incredible car, purchasing it in Australia during his tours and then bringing it back to the UK. 💲 Price: $520,000 💲 ⏳ Only one day left until the end of the auction! ⏳ #Lamborghini#Countach#LP400#RodStewart#RareCar#MusicianOwned#Auction#DreamCar#MuscleCar#Legendary#CollectorCar