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

Резултати

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

Пребарај: #paste

当前筛选 #paste清除筛选
Dishes.Cooking.Food

@cookingdish · Post #936 · 28.08.2025 г., 13:01

🍂Pumpkin Pasta!🍝 Ingredients: * 2 Pumpkins * 1 head Garlic * 1 tsp dry Oregano * 1 tbsp Paprika * 4 sprigs fresh Thyme * 1 sprig Sage * Olive oil * Pasta (of your choice) * Salt & Pepper, to taste * 1 Shallot * 1/3 cup White dry wine * 1 cup heavy Cream * 100 g. Parmigiano Reggiano #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #477 · 13.08.2024 г., 13:01

Caramelized Onion Pasta Ingredients: Oven: *300 g shallots *300 g vegan cream cheese *60 ml maple syrup *200 g smoked tofu *salt and pepper *Oil as desired Aside from that: *350g pasta *200 g dried tomatoes *1 bunch of fresh wild garlic *60 ml pasta water #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #475 · 11.08.2024 г., 13:02

Rice Noodle Spring Salad Ingredients: *1 carrot *100 g fresh red cabbage *1/2 cucumber *1/2 red onion *1 mango *250 g rice noodles Peanut sauce: *2 cm ginger *2 cloves of garlic *200 g peanut butter *20 ml sesame oil *50 ml maple syrup *50 ml soy sauce *150ml water Toppings: Chili flakes Coriander, mint peanuts #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #471 · 07.08.2024 г., 15:03

Roasted Vegetables Pasta Ingredients: *2 peppers *12 cherry tomatoes *150 g mushrooms *3 onions *6 cloves of garlic *1/2 zucchini Marinade: *Oil as desired *1 tsp chili *1 tsp salt *1 tbsp paprika *1 tbsp oregano *1 tbsp thyme *Price pepper Sauce: *200 g vegan cream cheese *82 tbsp tomato paste *2 handfuls of fresh basil *2 tbsp pasta water *1 tbsp balsamic vinegar Topping: *Pine nuts, roasted *Parmesan, vegan *Basil, fresh #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #459 · 28.07.2024 г., 15:48

You Need To Taste This Green Goddess Salad With Watermelon & Pasta Ingredients: *200 grams of watermelon *100 grams of cucumber *200 grams of pasta Dressing: *80 grams of spinach *1/2 bunch basil *1 clove of garlic *1/2 onion *50 grams of peas *40ml oil *25ml water *1 tbsp vinegar *1 tsp salt *40 grams of walnuts *juice of a lemon *1 tbsp yeast flakes *pinch of pepper toppings: Walnuts, Basil, Chili Flakes #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #406 · 12.06.2024 г., 13:01

Creamy Salmon Pasta Ingredients: *2 steaks of Salmon *50g. Butter *1 Shallot Onion *2 Fresh garlic cloves *1 1/2 Cup Cream. Heavy cream/whipping cream. *Fresh Dill or Parsley *1/2 TspLemon zest *Dry white Wine *Salt and black pepper. *Pasta Penne #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #397 · 07.06.2024 г., 12:59

Pasta Alla Vodka with Pancetta🧀 Ingredients: *350g. Rigatoni pasta (Can be replaced with penne pasta) *2 Tbsp Olive oil *150g. diced Pancetta *2 Shallot onion, finely chopped *3 Garlic cloves, finely chopped *1/2 Tsp Red-Chilli flakes *1/2 Tsp dried Oregano *1/2 cup Vodka *1 cup Tomato sauce *1/4 cup Tomato paste with basil pesto *2 cup Heavy cream *1/4 cup Parmesan cheese, plus more for serving *1 tablespoon roughly chopped fresh Basil *2 tablespoons roughly chopped Italian Parsley #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #349 · 13.04.2024 г., 16:59

PASTA WITH SHALLOTS & HERBS!🍝🌱 Ingredients: * Pasta * 1 cup Heavy cream * ¾ cup Parmesan cheese * 2 Shallots * 4 cloves Garlic * ¼ cup White wine * 4 tbsp Olive oil * 1 tbsp Butter * Fresh parsley * Chives * Salt/Pepper #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #341 · 06.04.2024 г., 12:04

ROASTED RED PEPPER PASTA! 🌶️ Ingredients: * 400 g. Giant Fusilli Pasta * 4 Red Bell Peppers * 2 Shallot onion * 1 head Garlic * Olive oil * 1 cup Heavy Cream * Red chili flakes * Italian herbs * 1 tbsp Tomato paste * 1 tbsp Butter * Salt/Pepper #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #339 · 03.04.2024 г., 12:05

AVOCADO SPINACH PASTA! ✨🥑 Ingredients: * 2 cloves Garlic * 1 Avocado * 130 g. Spinach * 50 g. Roasted pine nuts * Olive oil * Lemon juice * 100 ml. Water * Vegan parmesan * Cherry tomatoes * Salt/Pepper #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #335 · 31.03.2024 г., 14:19

ALFREDO RIGATONI! ✨ Ingredients: * Rigatoni * Shallot * Mushrooms * Garlic * Olive oil * White wine * Butter * Salt/Pepper * Cream * Fresh parsley * Parmesan cheese #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #318 · 19.03.2024 г., 15:00

KALE PASTA! 🍝 Ingredients: * 250 g. Pasta * 3 handfuls Kale * 1 Red onion * 3 cloves Garlic * Olive oil * 2 tbsp Tomato paste * Lemon juice * 400 ml. Vegan cream * Salt/Pepper * Vegan parmesan * Chili flakes #paste @dishes

Hashtags

ПретходнаСтраница 1 од 3Следна