Stop wasting time with for loops!

Stop wasting time with for loops!

Python Playground

3 дня назад

636 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@milihiba1664
@milihiba1664 - 10.11.2024 02:16

Great hack! very useful to optimize code 🔥
Keep it up and give us more Python hacks and tricks!

Ответить
@kaidaluck648
@kaidaluck648 - 10.11.2024 18:29

Not ordered, and the function itself has random sleep. This example is dumb.
It's true that for loops are slow in Python, but you could've shown actual alternatives like numpy for large lists, but this is just ridiculous.

Ответить
@alexanderschoch172
@alexanderschoch172 - 10.11.2024 20:54

please don't use parallelization if you don't know what you're doing. there's a lot more to consider than just speedup

Ответить
@PythonPlayground-rbh
@PythonPlayground-rbh - 10.11.2024 22:21

One important note: Before fully committing to parallelization, ensure it’s beneficial for your task. Set the number of processes carefully, so it doesn’t overload the system, especially if you need resources for other tasks. Avoid parallelization if tasks depend on each other sequentially, as this will reduce efficiency. Additionally, parallelization can sometimes slow down your code. For instance, if the overhead from switching between processes (context switching) exceeds the time required to execute the code itself, the performance may actually degrade rather than improve.

Ответить