This is nice, how would you go about as a performance noob? I can't imagine there's a line in the docs saying "this is slow!".
https://github.com/pyutils/line_profiler
You can literally see the hot spot of your code, then you can grind different algorithms or change the whole architecture to make it faster.
For example replace short for loops to list comprehensions, vectorize all numpy operations (only vectorize partially do not help the issue), using 'not any()' instead or 'all()' for boolean, etc.
Doing this for like 2 weeks, basically you can automatically recognize most bad code patterns at a glance.
If you see a piece of code like this, it rings the bell that the person has no idea what he/she is doing:
Bad Pattern:
my_list = np.array(xxx)
summed = []
for row in my_list:
summed.append(np.sum(row))
Worst Pattern: my_list = np.array(xxx)
def get_summed(arr):
return np.sum(arr)
summed = []
for i in range(len(my_list)):
summed.append(
get_summed(my_list[i])
)
Perfered: # np.array(xxx) is redundant
summed = np.sum(xxx, axis=1)
Same applies to all numpy operations.