Skip to content

Profile a whole script

When you don't yet know which function is slow, profile everything. With no targeting flags, profit run instruments every Python and C call in the script and prints them all, ranked by cumulative time — a map of where the time goes before you zoom in.

profit run my_script.py

examples/basic.py builds, serializes, and hashes a few thousand records:

profit run examples/basic.py

profit's full per-function profile of a script

The top rows are usually framework scaffolding — runpy, importlib, exec — because they sit at the top of the call tree and so accumulate the most time. Scan past them to your own functions (pipeline, serialize, fingerprint here), find the expensive one, then switch to -p to focus on it.

Sorting and trimming

--sort chooses the column to rank by and --limit caps the number of rows:

profit run my_script.py --sort calls --limit 10

--sort accepts cumulative (the default), tottime, or calls. See the CLI reference for every flag.

Profile a module

Use -m to profile a module the way python -m would run it:

profit run -m mypackage.cli

Next