Time a statement¶
A single call to a fast function is over too quickly to measure — one reading is mostly
noise. The usual workaround is to write a throwaway script that runs the thing a few
thousand times and profile that. profit timeit is that script, built in: hand it the
expression and it owns the loop, the one-time setup, and the iteration count, so you skip
the boilerplate (and skip deleting it afterward).
It works much like Python's built-in timeit module, but you get profit's full
per-call breakdown — mean, spread, min/max — instead of a single total.

--setup runs once before timing — use it to import modules or build inputs — and the
timed statement then runs in a tight loop. The iteration count is chosen automatically so
the whole run takes about 0.2 s (the count for this run is shown in the header).
Fixing the iteration count¶
Pass -n to run an exact number of iterations instead of the automatic count:
Comparing two statements¶
timeit takes the same -b/-p flags as profit run.
Import both functions in --setup and pit them against each other:
Next¶
- Compare implementations — the same delta view for functions in a script.
- Reading the output — the column legend.