TL;DR

With profiling you can check how long your code runs, how much memory it consumes & how many IO operations it performs.

There are several tools you can use to analyze the efficiency of your code, but there is one that is super easy to use, which also doesn't require you to add anything to your scripts >>> Scalene.


Primer

Profiling is a way of checking where your code is taking a long time or consuming a lot of memory.

If you type "Python Profiling" into YouTube the first video that comes up is this one:

Profiling and optimizing your Python code | Python tricks

It has a mere 47k views and is from 2018.

It suffices to say that profiling, aka. "looking into the nitty-gritty of your code", is not a hot topic. However, it can suddenly become tremendously important if you have a requirement to hit that 5ms response time in production but somehow your code takes 3x that long.

Let's look into a few ways I found to make stuff harder, better, faster, strongerđŸ˜‰

I'll address some general things first and then mention the tools I found and liked.

Modus Operandi

In the best case we don't need to profile, since we followed all the best practices right away and used our advanced skill of developer foresight to anticipate faults and breaking points.